mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
This commit is contained in:
parent
c87328f5cf
commit
bf14999eb2
2 changed files with 23 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
create_location, matching::resolve_path, Branch, History, Location,
|
||||
LocationChange, RouteContext, RouterIntegrationContext, State,
|
||||
create_location, matching::resolve_path, scroll_to_el, Branch, History,
|
||||
Location, LocationChange, RouteContext, RouterIntegrationContext, State,
|
||||
};
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
use crate::{unescape, Url};
|
||||
|
@ -302,6 +302,8 @@ impl RouterContextInner {
|
|||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
scroll_to_el(false);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -118,6 +118,11 @@ impl History for BrowserIntegration {
|
|||
.unwrap_throw();
|
||||
}
|
||||
// scroll to el
|
||||
scroll_to_el(loc.scroll);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn scroll_to_el(loc_scroll: bool) {
|
||||
if let Ok(hash) = leptos_dom::helpers::location().hash() {
|
||||
if !hash.is_empty() {
|
||||
let hash = js_sys::decode_uri(&hash[1..])
|
||||
|
@ -133,10 +138,9 @@ impl History for BrowserIntegration {
|
|||
}
|
||||
|
||||
// scroll to top
|
||||
if loc.scroll {
|
||||
if loc_scroll {
|
||||
leptos_dom::window().scroll_to_with_x_and_y(0.0, 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The wrapper type that the [`Router`](crate::Router) uses to interact with a [`History`].
|
||||
|
|
Loading…
Reference in a new issue