From b4369aa736c943a61c085b11472e82fed4c9e4d4 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Wed, 22 Jan 2025 23:54:07 +0530 Subject: [PATCH] handle query changes --- src/client/app/router.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/client/app/router.ts b/src/client/app/router.ts index 20f1d3d0..e22c545c 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -78,23 +78,22 @@ export function createRouter( if (inBrowser) { loc = normalizeHref(location.href) - const { pathname, search, hash } = new URL(href, fakeHost) + const { pathname, hash } = new URL(href, fakeHost) const currentLoc = new URL(loc, fakeHost) - if ( - pathname === currentLoc.pathname && - search === currentLoc.search && - hash !== currentLoc.hash - ) { + if (pathname === currentLoc.pathname && href !== loc) { history.pushState({}, '', href) - window.dispatchEvent( - new HashChangeEvent('hashchange', { - oldURL: currentLoc.href, - newURL: href - }) - ) - hash ? scrollTo(hash) : window.scrollTo(0, 0) + if (hash !== currentLoc.hash) { + window.dispatchEvent( + new HashChangeEvent('hashchange', { + oldURL: currentLoc.href, + newURL: href + }) + ) + + hash ? scrollTo(hash) : window.scrollTo(0, 0) + } return }