From cd3804c4b867dca100ff2d76b9a8d72ee33f77c8 Mon Sep 17 00:00:00 2001 From: Genki Takiuchi Date: Tue, 11 Feb 2025 06:16:19 +0900 Subject: [PATCH 1/3] Fire the hashchange event if the navigation is changing only location.hash --- packages/qwik-city/src/runtime/src/qwik-city-component.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/qwik-city/src/runtime/src/qwik-city-component.tsx b/packages/qwik-city/src/runtime/src/qwik-city-component.tsx index 49f801648d8..f7fa540cbb2 100644 --- a/packages/qwik-city/src/runtime/src/qwik-city-component.tsx +++ b/packages/qwik-city/src/runtime/src/qwik-city-component.tsx @@ -253,7 +253,12 @@ export const QwikCityProvider = component$((props) => { if (isBrowser) { // Use `location.href` because the lastDest signal is only updated on page navigates. if (type === 'link' && dest.href !== location.href) { - history.pushState(null, '', dest); + const withoutHash = dest.href.split('#')[0]; + if (location.href.startsWith(withoutHash + '#')) { + location.hash = dest.hash; + } else { + history.pushState(null, '', dest); + } } // Always scroll on same-page popstates, #hash clicks, or links. From 255e5c4e7d1fef15897e1c25ce2b6b2115c92800 Mon Sep 17 00:00:00 2001 From: Genki Takiuchi Date: Tue, 11 Feb 2025 07:46:20 +0900 Subject: [PATCH 2/3] Try to fix the test failure --- packages/qwik-city/src/runtime/src/qwik-city-component.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/qwik-city/src/runtime/src/qwik-city-component.tsx b/packages/qwik-city/src/runtime/src/qwik-city-component.tsx index f7fa540cbb2..4d5dc4d1d4c 100644 --- a/packages/qwik-city/src/runtime/src/qwik-city-component.tsx +++ b/packages/qwik-city/src/runtime/src/qwik-city-component.tsx @@ -253,8 +253,7 @@ export const QwikCityProvider = component$((props) => { if (isBrowser) { // Use `location.href` because the lastDest signal is only updated on page navigates. if (type === 'link' && dest.href !== location.href) { - const withoutHash = dest.href.split('#')[0]; - if (location.href.startsWith(withoutHash + '#')) { + if (location.href.startsWith(dest.href.split('#')[0])) { location.hash = dest.hash; } else { history.pushState(null, '', dest); From e2dd128ba55b0a2a5f21ad32ebf3dc3a8da038ff Mon Sep 17 00:00:00 2001 From: Genki Takiuchi Date: Tue, 11 Feb 2025 07:46:20 +0900 Subject: [PATCH 3/3] Try to fix the test failure --- packages/qwik-city/src/runtime/src/qwik-city-component.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/qwik-city/src/runtime/src/qwik-city-component.tsx b/packages/qwik-city/src/runtime/src/qwik-city-component.tsx index 4d5dc4d1d4c..01c9dedfb60 100644 --- a/packages/qwik-city/src/runtime/src/qwik-city-component.tsx +++ b/packages/qwik-city/src/runtime/src/qwik-city-component.tsx @@ -255,6 +255,9 @@ export const QwikCityProvider = component$((props) => { if (type === 'link' && dest.href !== location.href) { if (location.href.startsWith(dest.href.split('#')[0])) { location.hash = dest.hash; + if (location.hash === '') { + history.pushState(null, '', dest); + } } else { history.pushState(null, '', dest); }