chore: adjust fix for #3637

pull/3638/head
Divyansh Singh 8 months ago
parent 6b971a08f5
commit 2df9bab566

@ -64,11 +64,16 @@ export function createRouter(
}
async function go(href: string = inBrowser ? location.href : '/') {
const currentHash = inBrowser ? location.hash : ''
href = normalizeHref(href)
if ((await router.onBeforeRouteChange?.(href)) === false) return
updateHistory(href)
await loadPage(href)
await router.onAfterRouteChanged?.(href)
// do after the route is changed so location.hash in theme code is the new hash
if (new URL(href, fakeHost).hash !== currentHash) {
window.dispatchEvent(new Event('hashchange'))
}
}
let latestPendingPath: string | null = null
@ -211,12 +216,7 @@ export function createRouter(
window.scrollTo(0, 0)
}
} else {
go(href).then(() => {
// do after the route is changed so location.hash in theme code is the new hash
if (hash !== currentUrl.hash) {
window.dispatchEvent(new Event('hashchange'))
}
})
go(href)
}
}
}

Loading…
Cancel
Save