Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added scroll to top when we navigate #186

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/sycamore-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,16 @@ impl Integration for HistoryIntegration {
pathname.set(path.to_string());

// Update History API.
let history = web_sys::window().unwrap().history().unwrap();
let window = web_sys::window().unwrap();
let history = window.history().unwrap();
history
.push_state_with_url(
&JsValue::UNDEFINED,
"",
Some(pathname.get().as_str()),
)
.unwrap();
window.scroll_to_with_x_and_y(0.0, 0.0);
});
} else if Ok(&hash) != location.hash().as_ref() {
// Same origin, same path, different anchor.
Expand Down Expand Up @@ -259,10 +261,12 @@ pub fn navigate(url: &str) {
pathname.set(url.to_string());

// Update History API.
let history = web_sys::window().unwrap().history().unwrap();
let window = web_sys::window().unwrap();
let history = window.history().unwrap();
history
.push_state_with_url(&JsValue::UNDEFINED, "", Some(pathname.get().as_str()))
.unwrap();
window.scroll_to_with_x_and_y(0.0, 0.0);
});
}

Expand Down