Skip to content

Commit

Permalink
fix(guards): free instances only if navigation is confirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Mar 22, 2020
1 parent ba40b8f commit d0514e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/Link.ts
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions src/router.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {}
}
}

/**
Expand Down

0 comments on commit d0514e1

Please sign in to comment.