})
it('navigates if the location does not exist', async () => {
- const { router } = await newRouter()
+ const { router } = await newRouter({ routes: [routes[0]] })
const spy = jest.fn((to, from, next) => next())
router.beforeEach(spy)
await router.push('/idontexist')
path: '/parent',
})
})
+
+ // https://github.com/vuejs/vue-router-next/issues/404
+ it('works with named routes', async () => {
+ const history = createMemoryHistory()
+ const router = createRouter({
+ history,
+ routes: [
+ { name: 'foo', path: '/foo', redirect: '/bar' },
+ { path: '/bar', component: components.Bar },
+ ],
+ })
+ await expect(router.push('/foo')).resolves.toEqual(undefined)
+ const loc = router.currentRoute.value
+ expect(loc.name).toBe(undefined)
+ expect(loc.path).toBe('/bar')
+ expect(loc.redirectedFrom).toMatchObject({
+ name: 'foo',
+ path: '/foo',
+ })
+ })
})
describe('base', () => {
}
return pushWithRedirect(
assign(
- {},
- // having a path here would be a problem with relative locations but
- // at the same time it doesn't make sense for a redirect to be
- // relative (no name, no path) because it would create an infinite
- // loop. Since newTargetLocation must either have a `path` or a
- // `name`, this will never happen
- targetLocation,
+ {
+ query: targetLocation.query,
+ hash: targetLocation.hash,
+ params: targetLocation.params,
+ },
newTargetLocation,
{
state: data,