]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(router): invalidate ongoing navigation when unmounting
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 2 Aug 2021 09:18:43 +0000 (11:18 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 2 Aug 2021 09:18:43 +0000 (11:18 +0200)
src/router.ts

index 4895b884c98195520a940e9ff61f2e91ac50b05c..c0ada2be964dd25720a70f3e21f146dba2dbfabd 100644 (file)
@@ -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