diff --git a/src/client/app/router.ts b/src/client/app/router.ts index 42f12021..2be95f09 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -187,10 +187,13 @@ export function createRouter( search === currentUrl.search ) { // scroll between hash anchors in the same page - if (hash && hash !== currentUrl.hash) { - history.pushState(null, '', hash) - // still emit the event so we can listen to it in themes - window.dispatchEvent(new Event('hashchange')) + if (hash) { + // avoid duplicate history entries when the hash is same + if (hash !== currentUrl.hash) { + history.pushState(null, '', hash) + // still emit the event so we can listen to it in themes + window.dispatchEvent(new Event('hashchange')) + } // use smooth scroll when clicking on header anchor links scrollTo(link, hash, link.classList.contains('header-anchor')) }