diff --git a/router/src/history/mod.rs b/router/src/history/mod.rs index 4fdfde07e7..29f2092e90 100644 --- a/router/src/history/mod.rs +++ b/router/src/history/mod.rs @@ -37,13 +37,19 @@ pub struct BrowserIntegration {} impl BrowserIntegration { fn current() -> LocationChange { let loc = leptos_dom::helpers::location(); + let state = window() + .history() + .and_then(|h| h.state()) + .ok() + .and_then(|s| (!s.is_null()).then_some(s)); + LocationChange { value: loc.pathname().unwrap_or_default() + loc.search().unwrap_or_default().as_str() + loc.hash().unwrap_or_default().as_str(), replace: true, scroll: true, - state: State(None), + state: State(state), } } } diff --git a/router/src/history/state.rs b/router/src/history/state.rs index 06b60fa3d6..f0f2f47f4c 100644 --- a/router/src/history/state.rs +++ b/router/src/history/state.rs @@ -7,7 +7,7 @@ impl State { pub fn to_js_value(&self) -> JsValue { match &self.0 { Some(v) => v.clone(), - None => JsValue::UNDEFINED, + None => JsValue::NULL, } } }