]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(guards): free instances only if navigation is confirmed
authorEduardo San Martin Morote <posva13@gmail.com>
Sun, 22 Mar 2020 16:27:41 +0000 (17:27 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Sun, 22 Mar 2020 16:27:41 +0000 (17:27 +0100)
src/components/Link.ts
src/router.ts

index bd17b7d58e2c5c148b0b7d76f5f8c68426d15f30..afd3b20e375cb8f173efb8ff2f232047880f2e1f 100644 (file)
@@ -31,6 +31,7 @@ export function useLink(props: UseLinkOptions) {
   const href = computed(() => router.createHref(route.value))
 
   const activeRecordIndex = computed<number>(() => {
+    // TODO: handle children with empty path: they should relate to their parent
     const currentMatched = route.value.matched[route.value.matched.length - 1]
     return router.currentRoute.value.matched.findIndex(
       isSameRouteRecord.bind(null, currentMatched)
index a482e92f48ec0268868f296c55b36accda5505e8..4c7a82d90c3abdd180f7b091c4ee346a0e7a855a 100644 (file)
@@ -275,9 +275,6 @@ export function createRouter({
       for (const guard of record.leaveGuards) {
         guards.push(guardToPromiseFn(guard, to, from))
       }
-
-      // free the references
-      record.instances = {}
     }
 
     // run the queue of per route beforeRouteLeave guards
@@ -333,6 +330,14 @@ export function createRouter({
 
     // run the queue of per route beforeEnter guards
     await runGuardQueue(guards)
+
+    // TODO: add tests
+    //  this should be done only if the navigation succeeds
+    // if we redirect, it shouldn't be done because we don't know
+    for (const record of leavingRecords) {
+      // free the references
+      record.instances = {}
+    }
   }
 
   /**