{ path: '/p/:p', name: 'Param', component: components.Bar },
{ path: '/repeat/:r+', name: 'repeat', component: components.Bar },
{ path: '/to-p/:p', redirect: to => `/p/${to.params.p}` },
+ { path: '/redirect-with-param/:p', redirect: () => `/` },
{ path: '/before-leave', component: components.BeforeLeave },
{
path: '/parent',
})
})
+ it('discard params on string redirect', async () => {
+ const history = createMemoryHistory()
+ const router = createRouter({ history, routes })
+ await expect(router.push('/redirect-with-param/test')).resolves.toEqual(
+ undefined
+ )
+ expect(router.currentRoute.value).toMatchObject({
+ params: {},
+ query: {},
+ hash: '',
+ redirectedFrom: expect.objectContaining({
+ fullPath: '/redirect-with-param/test',
+ params: { p: 'test' },
+ }),
+ })
+ })
+
it('allows object in redirect', async () => {
const history = createMemoryHistory()
const router = createRouter({ history, routes })
newTargetLocation.indexOf('?') > -1 ||
newTargetLocation.indexOf('#') > -1
? (newTargetLocation = locationAsObject(newTargetLocation))
- : { path: newTargetLocation }
+ : // force empty params
+ { path: newTargetLocation }
+ // @ts-expect-error: force empty params when a string is passed to let
+ // the router parse them again
+ newTargetLocation.params = {}
}
if (