router
router copied to clipboard
Warning of invalid param for catch all route with named route redirect
Version
4.1.6
Reproduction link
Steps to reproduce
Navigate to a catch all route with a named route redirect
{
path: '/:pathMatch(.*)*',
redirect: { name: 'HOME' }
}
What is expected?
No warnings
What is actually happening?
Warning displayed: Discarded invalid param(s) "pathMatch" when navigating. See https://github.com/vuejs/router/blob/main/packages/router/CHANGELOG.md#414-2022-08-22 for more details.
This is due to the implicit parameter being passed during a redirection. You can workaround it by passing an empty object of Params alongside the name of the route: redirect: { name: 'home', params: {} }
or a function to pick the params you want: redirect: to => ({ name: '...', params: { id: to.id }})
I’m unsure if this warning can be avoided without removing it. Worst case scenario we can also mention the workaround in the warning
This works, thank you.
I have no strong opinion on this, I understand why the warning is there since I'm redirecting to a route that has no parameters so the workaround makes sense to me.
Hi @posva can I work on to try to fix it ?
Sure
@posva I would like to work on this
Is there a workaround for this issue?
It's the very first comment, I added some extra examples: https://github.com/vuejs/router/issues/1617#issuecomment-1320941431