Skip to content

Commit 8a01244

Browse files
committed
fix: fixed relative path hosting
This was leading to locale redirection loops, which affected the Perseus website. I'll push a new release for this immediately.
1 parent b7ace94 commit 8a01244

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/perseus/src/router/router_component.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
},
99
router::{PerseusRoute, RouteInfo, RouteVerdict},
1010
template::{RenderCtx, TemplateMap, TemplateNodeType},
11+
utils::get_path_prefix_client,
1112
ErrorPages,
1213
};
1314
use std::collections::HashMap;
@@ -152,12 +153,25 @@ pub(crate) fn perseus_router(
152153
// instead in the shell
153154
let router_state = &render_ctx.router; // We need this for interfacing with the router though
154155

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+
};
155169
// Prepare the initial view for hydration (because we have everything we need in
156170
// global window variables, this can be synchronous)
157171
let initial_view = get_initial_view(GetInitialViewProps {
158172
cx,
159173
// 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(),
161175
router_state: router_state.clone(),
162176
translations_manager: &translations_manager,
163177
error_pages: &error_pages,

0 commit comments

Comments
 (0)