Skip to content

Commit ad208ec

Browse files
authored
fix: bug with client-side routing no longer working due to different origin (#1899)
1 parent 72ad1d7 commit ad208ec

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

router/src/history/url.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,17 @@ impl TryFrom<&str> for Url {
3636
type Error = String;
3737

3838
fn try_from(url: &str) -> Result<Self, Self::Error> {
39-
let url =
40-
web_sys::Url::new(&format!("http://leptos{url}")).map_js_error()?;
39+
let url = web_sys::Url::new_with_base(
40+
&if url.starts_with("//") {
41+
let origin =
42+
leptos::window().location().origin().unwrap_or_default();
43+
format!("{origin}{url}")
44+
} else {
45+
url.to_string()
46+
},
47+
"http://leptos",
48+
)
49+
.map_js_error()?;
4150
Ok(Self {
4251
origin: url.origin(),
4352
pathname: url.pathname(),

0 commit comments

Comments
 (0)