|
|
@ -64,11 +64,16 @@ export function createRouter(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function go(href: string = inBrowser ? location.href : '/') {
|
|
|
|
async function go(href: string = inBrowser ? location.href : '/') {
|
|
|
|
|
|
|
|
const currentHash = inBrowser ? location.hash : ''
|
|
|
|
href = normalizeHref(href)
|
|
|
|
href = normalizeHref(href)
|
|
|
|
if ((await router.onBeforeRouteChange?.(href)) === false) return
|
|
|
|
if ((await router.onBeforeRouteChange?.(href)) === false) return
|
|
|
|
updateHistory(href)
|
|
|
|
updateHistory(href)
|
|
|
|
await loadPage(href)
|
|
|
|
await loadPage(href)
|
|
|
|
await router.onAfterRouteChanged?.(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
|
|
|
|
let latestPendingPath: string | null = null
|
|
|
@ -211,12 +216,7 @@ export function createRouter(
|
|
|
|
window.scrollTo(0, 0)
|
|
|
|
window.scrollTo(0, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
go(href).then(() => {
|
|
|
|
go(href)
|
|
|
|
// 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'))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|