@@ -8,6 +8,7 @@ use crate::{
8
8
} ,
9
9
router:: { PerseusRoute , RouteInfo , RouteVerdict } ,
10
10
template:: { RenderCtx , TemplateMap , TemplateNodeType } ,
11
+ utils:: get_path_prefix_client,
11
12
ErrorPages ,
12
13
} ;
13
14
use std:: collections:: HashMap ;
@@ -152,12 +153,25 @@ pub(crate) fn perseus_router(
152
153
// instead in the shell
153
154
let router_state = & render_ctx. router ; // We need this for interfacing with the router though
154
155
156
+ // Get the current path, removing any base paths to avoid relative path locale
157
+ // redirection loops (in previous versions of Perseus, we used Sycamore to
158
+ // get the path, and it strips this out automatically)
159
+ // Note that this does work with full URL paths, because
160
+ // `get_path_prefix_client` does automatically get just the pathname
161
+ // component.
162
+ let path_prefix = get_path_prefix_client ( ) ;
163
+ let path = web_sys:: window ( ) . unwrap ( ) . location ( ) . pathname ( ) . unwrap ( ) ;
164
+ let path = if path. starts_with ( & path_prefix) {
165
+ path. strip_prefix ( & path_prefix) . unwrap ( )
166
+ } else {
167
+ & path
168
+ } ;
155
169
// Prepare the initial view for hydration (because we have everything we need in
156
170
// global window variables, this can be synchronous)
157
171
let initial_view = get_initial_view ( GetInitialViewProps {
158
172
cx,
159
173
// Get the path directly, in the same way the Sycamore router's history integration does
160
- path : web_sys :: window ( ) . unwrap ( ) . location ( ) . pathname ( ) . unwrap ( ) ,
174
+ path : path . to_string ( ) ,
161
175
router_state : router_state. clone ( ) ,
162
176
translations_manager : & translations_manager,
163
177
error_pages : & error_pages,
0 commit comments