From 3eb951dd03fce0dd3530baf7476ddaa169ca5945 Mon Sep 17 00:00:00 2001 From: Luxalpa Date: Sat, 6 Jan 2024 12:54:06 +0100 Subject: [PATCH 1/2] fix router forgetting about state --- router/src/history/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router/src/history/mod.rs b/router/src/history/mod.rs index 4fdfde07e7..82c19086a7 100644 --- a/router/src/history/mod.rs +++ b/router/src/history/mod.rs @@ -43,7 +43,7 @@ impl BrowserIntegration { + loc.hash().unwrap_or_default().as_str(), replace: true, scroll: true, - state: State(None), + state: State(window().history().and_then(|h| h.state()).ok()), } } } From 581dc904ee426da72cd810ccf9751dd8755c133d Mon Sep 17 00:00:00 2001 From: Luxalpa Date: Sat, 6 Jan 2024 13:43:52 +0100 Subject: [PATCH 2/2] fix state being undefined instead of null and handle null -> None --- router/src/history/mod.rs | 8 +++++++- router/src/history/state.rs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/router/src/history/mod.rs b/router/src/history/mod.rs index 82c19086a7..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(window().history().and_then(|h| h.state()).ok()), + 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, } } }