解决vue路由重复的问题 vue-router.esm.js?8c4f:2065 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “/index”.
解决办法
1 在router/index.js下添加这些代码

import Router from ‘vue-router’
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
return routerPush.call(this, location).catch(error=> error)
}
在Vue应用中遇到Vue Router导致的'NavigationDuplicated'错误?本文提供解决方案。只需在router/index.js文件下添加代码,覆盖默认的push方法,确保错误被优雅地捕获和处理。这样可以避免多余的导航到当前位置,如'/index'。
2463

被折叠的 条评论
为什么被折叠?



