Преглед изворни кода

feat: add scroll to 0 for web router

Jonathan Kelley пре 2 година
родитељ
комит
7e45f2aa04
1 измењених фајлова са 5 додато и 0 уклоњено
  1. 5 0
      packages/router/src/components/link.rs

+ 5 - 0
packages/router/src/components/link.rs

@@ -126,6 +126,11 @@ pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element {
                     if let Some(service) = svc {
                         log::trace!("Pushing route to {}", to);
                         service.push_route(to, cx.props.title.map(|f| f.to_string()), None);
+
+                        #[cfg(feature = "web")]
+                        {
+                            web_sys::window().unwrap().scroll_to_with_x_and_y(0.0, 0.0);
+                        }
                     } else {
                         log::error!(
                             "Attempted to create a Link to {} outside of a Router context", cx.props