Skip to content

Catch all route (asterisk route) error when matched path is empty string #3062

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

Closed
adi-zz opened this issue Dec 11, 2019 · 3 comments
Closed

Comments

@adi-zz
Copy link
Contributor

adi-zz commented Dec 11, 2019

Version

3.1.3

Reproduction link

https://codesandbox.io/s/vue-template-c3dox

Steps to reproduce

Go to https://codesandbox.io/s/vue-template-c3dox

Click on link go to /anything/123 .
Click on button go to [current url]?foo=bar.
You get to page /anything/123?foo=bar - as expected.

Now, click on link go to /anything/ .
Click on button go to [current url]?foo=bar.
You get to page /?foo=bar.

What is expected?

You should get to page /anything/?foo=bar.

What is actually happening?

You get to /?foo=bar.
And console says: "[vue-router] missing param for named route "catchAllRoute": Expected "0" to be defined".

@posva
Copy link
Member

posva commented Dec 11, 2019

Copying the normalized route and passing that to push isn't really valid. Use this instead

const newRoute = {
        path: this.$route.path,
        query: { foo: "bar" }
      }; 

@adi-zz
Copy link
Contributor Author

adi-zz commented Dec 12, 2019

@posva

Documentation says you can use "named route" when calling router.push. Is it fair to say that a remark should be added in the doc saying "named route" + router.push is not supported when the named route is a catch all route?

Because:

this.$router.push({
  name: "catchAllRoute",
  params: { pathMatch: "" }
});
// => [vue-router] missing param for named route "catchAllRoute": Expected "0" to be defined

Although:

this.$router.push({
  name: "catchAllRoute",
  params: { pathMatch: "bla" }
});
// => works as expected, but what if
//       I need to redirect to a path with `pathMatch` being the empty string?

this.$router.push({
  name: "catchAllRoute",
  params: { 0: "" }
});
// => works as expected, by as I understand `0` should not be used
//       https://github.com/vuejs/vue-router/issues/2742#issuecomment-487026392

Needless to say, I would prefer "named route" + router.push to do work for catch all routes.

@adi-zz
Copy link
Contributor Author

adi-zz commented Dec 19, 2019

So @posva isn't this a bug?
cc @LinusBorg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants