Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning when using pathMatch #951

Closed
narwajea opened this issue May 17, 2021 · 3 comments
Closed

Warning when using pathMatch #951

narwajea opened this issue May 17, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@narwajea
Copy link

Version

4.0.8

Reproduction link

https://jsfiddle.net/cwbe2yq3/

Steps to reproduce

Open JSFiddle
Open console
Click on "Home" link

What is expected?

No warning in console

What is actually happening?

Warning in console:
[Vue Router warn]: Path "/dev" was passed with params but they will be ignored. Use a named route alongside params instead.

@posva posva added the contribution welcome The team would welcome a contribution from the community for this issue label May 17, 2021
@PeterAlfredLee
Copy link
Contributor

Hi, @narwajea
This might be a workaround: use name and params in redirect instead of path.
see this: https://jsfiddle.net/h8c6gojt/1

const router = createRouter({
  history: createWebHistory(),
  routes: [
  {
    name: "home",
    path: "/:env",
    component: Home,
  },
  { path: "/:pathMatch(.*)*", redirect: {name: "home", params: {env: "dev"}}},
  ],
})

@narwajea
Copy link
Author

@PeterAlfredLee thank you, it works indeed, as suggested in the warning message. But I think it is hiding the real issue because in that case, no warning should be displayed.

@PeterAlfredLee
Copy link
Contributor

Hi @narwajea . I think the warning is useful here.

A params can be parsed from the path: "/:pathMatch(.*)*". At the same time, you are using redirect, this will lead to a recursive call of router.resolve. The new call is using pathMatch(.*) as the params and using /dev as path. In this case, a new params can be parsed from /dev, which is different with the existing one "/:env". That's why we got a warning here.

In short words, a route like this:

{ path: "/", redirect: 'dev' }

will not generate any warnings. This is complicated. Hope this helps.

Maybe we can improve the warning message here. Maybe we can use a warning like Path "${(rawLocation as any).path}" was passed with params "${(rawLocation as any).params}" but they will be ignored. Please use a named route alongside params instead. WDYT? @posva

@posva posva added bug Something isn't working and removed contribution welcome The team would welcome a contribution from the community for this issue labels May 27, 2021
@posva posva closed this as completed in bed24df May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants