From: Eduardo San Martin Morote Date: Mon, 2 Aug 2021 09:18:43 +0000 (+0200) Subject: fix(router): invalidate ongoing navigation when unmounting X-Git-Tag: v4.0.11~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8fb7d0ab1694fe86edbd52668f84fb9bb9f4dcf;p=thirdparty%2Fvuejs%2Frouter.git fix(router): invalidate ongoing navigation when unmounting --- diff --git a/src/router.ts b/src/router.ts index 4895b884..c0ada2be 100644 --- a/src/router.ts +++ b/src/router.ts @@ -923,7 +923,7 @@ export function createRouter(options: RouterOptions): Router { markAsReady() } - let removeHistoryListener: () => void + let removeHistoryListener: () => void | undefined // attach listener to history to trigger navigations function setupListeners() { removeHistoryListener = routerHistory.listen((to, _from, info) => { @@ -1195,8 +1195,11 @@ export function createRouter(options: RouterOptions): Router { installedApps.add(app) app.unmount = function () { installedApps.delete(app) + // the router is not attached to an app anymore if (installedApps.size < 1) { - removeHistoryListener() + // invalidate the current navigation + pendingLocation = START_LOCATION_NORMALIZED + removeHistoryListener && removeHistoryListener() currentRoute.value = START_LOCATION_NORMALIZED started = false ready = false