From 5763938eb34a090d4cd89db30835c0bd1b91d173 Mon Sep 17 00:00:00 2001 From: Luke <37006668+lukechu10@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:18:54 +0200 Subject: [PATCH] Fix router on different pathname and hash triggers hard refresh (#700) Fix router different pathname and hash trigger hard refresh --- packages/sycamore-router/src/router.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/sycamore-router/src/router.rs b/packages/sycamore-router/src/router.rs index 7b6ebc7c..4f35641f 100644 --- a/packages/sycamore-router/src/router.rs +++ b/packages/sycamore-router/src/router.rs @@ -81,9 +81,7 @@ impl Integration for HistoryIntegration { let meta_keys_pressed = meta_keys_pressed(ev.unchecked_ref::()); if !meta_keys_pressed && location.origin() == Ok(origin) { - if location.hash().as_ref() != Ok(&hash) { - // Same origin, same path, different anchor. Use default browser behavior. - } else if location.pathname().as_ref() != Ok(&a_pathname) { + if location.pathname().as_ref() != Ok(&a_pathname) { // Same origin, different path. Navigate to new page. ev.prevent_default(); PATHNAME.with(|pathname| { @@ -100,6 +98,8 @@ impl Integration for HistoryIntegration { .unwrap_throw(); window().scroll_to_with_x_and_y(0.0, 0.0); }); + } else if location.hash().as_ref() != Ok(&hash) { + // Same origin, same pathname, different hash. Use default browser behavior. } else { // Same page. Do nothing. ev.prevent_default();