Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: setup history listeners once
Fix #1344
  • Loading branch information
posva committed Mar 16, 2022
1 parent 76f42f9 commit faa8562
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/router.ts
Expand Up @@ -938,9 +938,11 @@ export function createRouter(options: RouterOptions): Router {
markAsReady()
}

let removeHistoryListener: () => void | undefined
let removeHistoryListener: undefined | null | (() => void)
// attach listener to history to trigger navigations
function setupListeners() {
// avoid setting up listeners twice due to an invalid first navigation
if (removeHistoryListener) return
removeHistoryListener = routerHistory.listen((to, _from, info) => {
// cannot be a redirect route because it was in history
const toLocation = resolve(to) as RouteLocationNormalized
Expand Down Expand Up @@ -1220,6 +1222,7 @@ export function createRouter(options: RouterOptions): Router {
// invalidate the current navigation
pendingLocation = START_LOCATION_NORMALIZED
removeHistoryListener && removeHistoryListener()
removeHistoryListener = null
currentRoute.value = START_LOCATION_NORMALIZED
started = false
ready = false
Expand Down

0 comments on commit faa8562

Please sign in to comment.