{ path: '/foo', component: Foo },
{
path: '/guard/:n',
+ alias: '/guard-alias/:n',
component: {
...Foo,
beforeRouteEnter,
expect(beforeRouteEnter).toHaveBeenCalledTimes(1)
})
+ it('does not call beforeRouteEnter guards on navigation between aliases', async () => {
+ const router = createRouter({ routes })
+ const spy = jest.fn()
+ beforeRouteEnter.mockImplementation(spy)
+ await router.push('/guard/valid')
+ expect(beforeRouteEnter).toHaveBeenCalledTimes(1)
+ await router.push('/guard-alias/valid')
+ expect(beforeRouteEnter).toHaveBeenCalledTimes(1)
+ await router.push('/guard-alias/other')
+ expect(beforeRouteEnter).toHaveBeenCalledTimes(1)
+ await router.push('/guard/other')
+ expect(beforeRouteEnter).toHaveBeenCalledTimes(1)
+ })
+
it('calls beforeRouteEnter guards on navigation for nested views', async () => {
const router = createRouter({ routes })
await router.push('/nested/nested/foo')
const recordTo = to.matched[i]
if (recordTo) {
// the type doesn't matter because we are comparing per reference
- if (from.matched.indexOf(recordTo as any) < 0)
+ if (!from.matched.find(isSameRouteRecord.bind(null, recordTo))) {
enteringRecords.push(recordTo)
+ }
}
}