From: Eduardo San Martin Morote Date: Wed, 16 Mar 2022 15:44:44 +0000 (+0100) Subject: fix: setup history listeners once X-Git-Tag: v4.0.15~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=faa85624d37367c638fb9272a4130d8524143120;p=thirdparty%2Fvuejs%2Frouter.git fix: setup history listeners once Fix #1344 --- diff --git a/src/router.ts b/src/router.ts index 9a87439b..dee1f9b9 100644 --- a/src/router.ts +++ b/src/router.ts @@ -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 @@ -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