{ path: '/foo', component: Foo },
{
path: '/guard/:go',
+ alias: '/guard-alias/:go',
component: {
...Foo,
beforeRouteUpdate,
expect(beforeRouteUpdate).toHaveBeenCalledTimes(1)
})
+ it('calls beforeRouteUpdate guards when changing params with alias', async () => {
+ const router = createRouter({ routes })
+ beforeRouteUpdate.mockImplementationOnce(noGuard)
+ await router.push('/guard/valid')
+ // not called on initial navigation
+ expect(beforeRouteUpdate).not.toHaveBeenCalled()
+ // simulate a mounted route component
+ router.currentRoute.value.matched[0].instances.default = {} as any
+ await router.push('/guard-alias/other')
+ expect(beforeRouteUpdate).toHaveBeenCalledTimes(1)
+ })
+
it('does not call beforeRouteUpdate guard if the view is not mounted', async () => {
const router = createRouter({ routes })
beforeRouteUpdate.mockImplementationOnce(noGuard)
computed,
} from 'vue'
import { RouteRecord, RouteRecordNormalized } from './matcher/types'
-import { parseURL, stringifyURL, isSameRouteLocation } from './location'
+import {
+ parseURL,
+ stringifyURL,
+ isSameRouteLocation,
+ isSameRouteRecord,
+} from './location'
import { extractComponentsGuards, guardToPromiseFn } from './navigationGuards'
import { warn } from './warning'
import { RouterLink } from './RouterLink'
for (let i = 0; i < len; i++) {
const recordFrom = from.matched[i]
if (recordFrom) {
- if (to.matched.indexOf(recordFrom) < 0) leavingRecords.push(recordFrom)
- else updatingRecords.push(recordFrom)
+ if (to.matched.find(isSameRouteRecord.bind(null, recordFrom)))
+ updatingRecords.push(recordFrom)
+ else leavingRecords.push(recordFrom)
}
const recordTo = to.matched[i]
if (recordTo) {