router icon indicating copy to clipboard operation
router copied to clipboard

Warning of invalid param for catch all route with named route redirect

Open jfrs opened this issue 2 years ago • 7 comments

Version

4.1.6

Reproduction link

jsfiddle.net/z0kytrqj/16/

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.

jfrs avatar Nov 19 '22 11:11 jfrs

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

posva avatar Nov 19 '22 18:11 posva

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.

jfrs avatar Nov 19 '22 23:11 jfrs

Hi @posva can I work on to try to fix it ?

EliphazBouye avatar Feb 28 '23 00:02 EliphazBouye

Sure

posva avatar Feb 28 '23 07:02 posva

@posva I would like to work on this

ashutosh887 avatar Mar 01 '23 12:03 ashutosh887

Is there a workaround for this issue?

bblanchon avatar Jul 06 '23 08:07 bblanchon

It's the very first comment, I added some extra examples: https://github.com/vuejs/router/issues/1617#issuecomment-1320941431

posva avatar Jul 06 '23 08:07 posva