Skip to content

using addRoutes() when you already have a wildcard route fails to detect if the CURRENT url matches one of the new routes #1862

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
jakesgordon opened this issue Nov 4, 2017 · 2 comments
Labels
fixed on 4.x This issue has been already fixed on the v4 but exists in v3 group[dynamic routing] Issues regarding dynamic routing support (eg add, replace, remove routes dynamically) has PR has workaround improvement

Comments

@jakesgordon
Copy link

Version

3.0.1

Reproduction link

https://jsfiddle.net/c4jkw82o/5/

Steps to reproduce

The JSFiddle shows the broken case.

Given an app/router that includes a wildcard '*' route, calling addRoutes() to dynamically add more routes does not correctly render the page if the CURRENT url matches one of the newly added routes.

If you comment out the wildcard '*' route and re-run then it works as expected.

What is expected?

The "Test" component should be rendered

What is actually happening?

The "NotFound" component is rendered


BACKGROUND...

I am attempting to use webpack code splitting to keep all of my test related code in a different bundle, that includes vue components that are only used in the tests. I wanted to try to dynamically add my "/test" route from within this separate bundle and discovered that serving up that page showed my 404 not found component instead of my (top level) test component.

DEBUGGING NOTES...

From what I can tell, when the router is first constructed - in my main application.js bundle - it checks against the current URL "/test" and matches the wildcard route as $router.currentRoute. Later when the separate test.js bundle adds the new routes it checks again, this time it matches the new test route and tries to transition, but during confirmTransition() it decides that isSameRoute() is true (both matches had path=/test) and does not update.

... after checking isSameRoute() there is actually a small attempt to see if the routes were dynamically changed...

// in the case the route map has been dynamically appended to
route.matched.length === current.matched.length

.. but in this case this check also (incorrectly) returns true because while the length is the same (1) the details of route.matched[0] are different - current.matched is pointing to the wildcard route but route.matched is pointing to the new test route.

P.S. THANK YOU FOR ALL YOUR WORK ON VUE - it is awesome!

@lingarajuanilkumar
Copy link

May I know what is the workaround?

@posva posva added the group[dynamic routing] Issues regarding dynamic routing support (eg add, replace, remove routes dynamically) label Mar 26, 2019
@posva posva added the has PR label Apr 11, 2019
@posva posva added the fixed on 4.x This issue has been already fixed on the v4 but exists in v3 label Apr 20, 2020
@posva
Copy link
Member

posva commented Jun 24, 2020

This should be fixed with #3228

@posva posva closed this as completed Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed on 4.x This issue has been already fixed on the v4 but exists in v3 group[dynamic routing] Issues regarding dynamic routing support (eg add, replace, remove routes dynamically) has PR has workaround improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants