Home > Article > Web Front-end > How to solve the problem "Error: Avoided redundant navigation to current location" when using vue-router in Vue application?
When using vue-router in a Vue application, the error message "Error: Avoided redundant navigation to current location" sometimes appears. This error message means "avoiding redundant navigation to the current location" and is usually caused by clicking the same link repeatedly or using the same routing path. So, how to solve this problem?
When defining router-link or using programmatic navigation, you can add the exact attribute, which means exact matching of routes. For example:
<router-link to="/" exact>首页</router-link>
In some cases, we may need to allow users to jump from one page to another without browsing. To add a new record to the router's history, you can use the router's replace method. For example:
router.replace('/login')
If the route update in the component does not respond in time, you can use the beforeRouteUpdate method to manually update the component. For example:
beforeRouteUpdate (to, from, next) { if (to.path === from.path) { next(false) } else { this.$forceUpdate() next() } }
Repeatedly clicking the same link or using the same routing path will result in the "Error: Avoided redundant navigation to current location" error. . We can use some techniques to prevent users from clicking repeatedly, such as adding disabled attributes to links or using throttling functions.
Summary:
When using vue-router in a Vue application, the "Error: Avoided redundant navigation to current location" error message may appear because the route jumps repeatedly or the same route is used. caused by the path. We can solve this problem by using the exact modifier, replace attribute, beforeRouteUpdate method, or avoiding repeated clicks.
The above is the detailed content of How to solve the problem "Error: Avoided redundant navigation to current location" when using vue-router in Vue application?. For more information, please follow other related articles on the PHP Chinese website!