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

Using .addRoutes when you've got a wildcard route for 404s does not work #1176

Closed
Dadibom opened this issue Feb 17, 2017 · 11 comments
Closed

Comments

@Dadibom
Copy link

Dadibom commented Feb 17, 2017

Vue.js / vue-router versions

2.1.10 / 2.2.1

Reproduction Link

https://jsfiddle.net/ytezcvzq/4/

Steps to reproduce

Add a new route when you've already got a wildcard route to display page not found messages

What is Expected?

The new route should be matched before the wildcard route

What is actually happening?

the wildcard route is matched first, meaning addRoutes does not work

@Dadibom
Copy link
Author

Dadibom commented Feb 17, 2017

This happens even when the wildcard route is a child route of '/', which is kinda strange. I do think that "root" routes should have higher priority than child routes.

@posva
Copy link
Member

posva commented Feb 18, 2017

Hey, thanks for opening the issue.
This is indeed a caveat of dynamically added routes. FTM you'll have to add the wild card route after any other route.

ping @fnlctrl @yyx990803

@Dadibom
Copy link
Author

Dadibom commented Feb 18, 2017

Maybe there could be an option to prepend the new routes instead of appending them?

@fnlctrl
Copy link
Member

fnlctrl commented Feb 18, 2017

Hmm maybe dynamically added routes should have higher priority than the statically defined ones?

@Dadibom Yeah an option seems nice

@LinusBorg
Copy link
Member

LinusBorg commented Feb 22, 2017

Another option would be to optionally make addRoutes override old routes (.addRoutes(newRoutes,{ override: true })), so you can construct a new routes array externally the way you need it?

@posva
Copy link
Member

posva commented Feb 22, 2017

We can also keep track of any asterisk route (path: '*') so dynamically added routes are always added before that one.
People will still have issues if there's some route with foo-* and they dynamically add routes like foo-lol and foo-bar but I don't see a real world example about a partial asterisk while having an asterisk route is very common

@Dadibom
Copy link
Author

Dadibom commented Feb 23, 2017

I'd be fine with any of the solutions mentioned, but I think the most transparent one would be appendRoutes / prependRoutes / replaceRoutes

@DanielPe05
Copy link

Is there an update for this? I just ran into it. I think that keeping track of path: '*' and adding dynamic routes before it as suggested by @posva is the simplest, quickest solution. However as a more complete fix that would give more flexibilities, I think being able to appendRoute/prependRoute makes more sense.

@Dadibom
Copy link
Author

Dadibom commented Jun 13, 2017

well... i've got two main views (routes) that each have their own layouts. the * route is a child route to my main view. when i add the second view (admin), i still cannot access it. prepend/replace would be great.

@wasdujk
Copy link

wasdujk commented Aug 31, 2018

@LinusBorg Your answer solved my doubts. But I didn't find any information about { override: true } in the document

@LinusBorg
Copy link
Member

Because it is a suggestion, not an existing feature.

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

No branches or pull requests

7 participants