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

addRoute If more than 11 routes are dynamically added, the first added route will be invalidated by directly accessing the url #1643

Closed
wangronglei opened this issue Dec 27, 2022 · 3 comments

Comments

@wangronglei
Copy link

wangronglei commented Dec 27, 2022

First of all sorry, my English is not good

Version

4.1.6

Reproduction link

github.com

After packaging in our project, it is normal, and this problem will occur in the development mode

Steps to reproduce

npm install
npm start

I added routes via API "router.beforeEach" and 'router.addRoute' dynamically. After 11 routes were added to the router object, an extra route makes the first route invalid. It seems like the Vue Route maintains a queue which has maximun capacity of 11 routes.
In my demo, there are 11 routes existed, which are from 'view1' to 'view11', and 'view1' is the first added route. Every routes could be accessed successfully. After 12th route added, I launched the demo and accessing "http://localhost:8080/view1".
Then I got a warn which prints "[Vue Router warn]: Unexpected error when starting the router: Error: Infinite redirect in navigation guard", and the corresponding page was failed to loaded. The 13th route makes the 2nd route invalid and so on.

What is expected?

Direct access to "http://localhost:8080/view1" page appears

What is actually happening?

[Vue Router warn]: Unexpected error when starting the router: Error: Infinite redirect in navigation guard

Copy link
Member

posva commented Dec 27, 2022

I think the problem comes from https://github.com/wangronglei/vue3-demo/blob/main/src/common/dynamic-load/index.js#L17, it makes no sense to redirect to the same location we are going to, instead, return true. That's what the warning is telling you.

@posva posva closed this as completed in 376edd3 Dec 27, 2022
@posva
Copy link
Member

posva commented Dec 27, 2022

BTW, you should call router.push() when adding new routes if you want to take them into account for the navigation and cancel the existing navigation.

More at https://router.vuejs.org/guide/advanced/dynamic-routing.html#dynamic-routing, usu

@wangronglei
Copy link
Author

BTW, you should call router.push() when adding new routes if you want to take them into account for the navigation and cancel the existing navigation.

More at https://router.vuejs.org/guide/advanced/dynamic-routing.html#dynamic-routing, usu

Thank you for your reply

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