Skip to content

Commit

Permalink
fix: remember router state (fixes #2164) (#2165)
Browse files Browse the repository at this point in the history
  • Loading branch information
luxalpa authored Jan 11, 2024
1 parent 2d70229 commit 10bbeea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion router/src/history/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion router/src/history/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down

0 comments on commit 10bbeea

Please sign in to comment.