children: [],
aliasOf: undefined,
components: { default: {} },
- leaveGuards: [],
- updateGuards: [],
+ leaveGuards: expect.any(Set),
+ updateGuards: expect.any(Set),
instances: {},
meta: {},
name: undefined,
beforeEnter,
children: [{ path: '/child' }],
components: { default: {} },
- leaveGuards: [],
- updateGuards: [],
+ leaveGuards: expect.any(Set),
+ updateGuards: expect.any(Set),
instances: {},
meta: { foo: true },
name: 'name',
beforeEnter,
children: [{ path: '/child' }],
components: { one: {} },
- leaveGuards: [],
- updateGuards: [],
+ leaveGuards: expect.any(Set),
+ updateGuards: expect.any(Set),
instances: {},
meta: { foo: true },
name: 'name',
*/
function createTestComponent(key: string) {
return defineComponent({
+ name: key,
template: `
<div :id="key">
{{ key }}
</router-view>
</template>
<template v-else-if="testCase === 'keyed'">
- <router-view :key="$route.query.foo" class="view" />
+ <router-view :key="$route.query.foo || undefined" class="view" />
</template>
<template v-else-if="testCase === 'keepalivekeyed'">
<router-view v-slot="{ Component }" >
<keep-alive>
- <component :is="Component" :key="$route.query.foo" class="view" />
+ <component :is="Component" :key="$route.query.foo || undefined" class="view" />
</keep-alive>
</router-view>
</template>
app.use(router)
+// @ts-ignore
+window.r = router
+
app.mount('#app')
.expect.element('#logs')
.text.to.equal(
[
- // lol
+ // to force new lines formatting
`${name}: update /f/2 - /f/2`,
`${name}: setup:update /f/2 - /f/2`,
].join('\n')
to.instances[name] = instance
// the component instance is reused for a different route or name so
// we copy any saved update or leave guards
- if (from && instance === oldInstance) {
+ if (from && from !== to && instance && instance === oldInstance) {
to.leaveGuards = from.leaveGuards
to.updateGuards = from.updateGuards
}
props: normalizeRecordProps(record),
children: record.children || [],
instances: {},
- leaveGuards: [],
- updateGuards: [],
+ leaveGuards: new Set(),
+ updateGuards: new Set(),
enterCallbacks: {},
components:
'components' in record
*
* @internal
*/
- leaveGuards: NavigationGuard[]
+ leaveGuards: Set<NavigationGuard>
/**
* Registered update guards
*
* @internal
*/
- updateGuards: NavigationGuard[]
+ updateGuards: Set<NavigationGuard>
/**
* Registered beforeRouteEnter callbacks passed to `next` or returned in guards
*
import { isESModule } from './utils'
import { warn } from './warning'
-function registerGuard(list: NavigationGuard[], guard: NavigationGuard) {
+function registerGuard(
+ record: RouteRecordNormalized,
+ name: 'leaveGuards' | 'updateGuards',
+ guard: NavigationGuard
+) {
const removeFromList = () => {
- const index = list.indexOf(guard)
- if (index > -1) list.splice(index, 1)
+ record[name].delete(guard)
}
onUnmounted(removeFromList)
onDeactivated(removeFromList)
onActivated(() => {
- const index = list.indexOf(guard)
- if (index < 0) list.push(guard)
+ record[name].add(guard)
})
- list.push(guard)
+ record[name].add(guard)
}
/**
return
}
- registerGuard(activeRecord.leaveGuards, leaveGuard)
+ registerGuard(activeRecord, 'leaveGuards', leaveGuard)
}
/**
return
}
- registerGuard(activeRecord.updateGuards, updateGuard)
+ registerGuard(activeRecord, 'updateGuards', updateGuard)
}
export function guardToPromiseFn(
// leavingRecords is already reversed
for (const record of leavingRecords) {
- for (const guard of record.leaveGuards) {
+ record.leaveGuards.forEach(guard => {
guards.push(guardToPromiseFn(guard, to, from))
- }
+ })
}
const canceledNavigationCheck = checkCanceledNavigationAndReject.bind(
)
for (const record of updatingRecords) {
- for (const guard of record.updateGuards) {
+ record.updateGuards.forEach(guard => {
guards.push(guardToPromiseFn(guard, to, from))
- }
+ })
}
guards.push(canceledNavigationCheck)