目录
1、方案一
- 1、方案一
- 2、方案二
- 3、方案三
- 4、方案四
- 5、总结
- 6、相关链接
在router文件夹下的index.js文件中添加如下代码。
Vue.use(Router) const router = new Router({ routes }); // 添加的的代码 const VueRouterPush = Router.prototype.push; Router.prototype.push = function push (to) { return VueRouterPush.call(this, to).catch(err => err); }; // 添加的的代码2、方案二
在跳转时,判断跳转路由和当前路由是否一致,避免重复跳转产生问题。
toMenu (item) { if (this.$route.path !== item.url) { this.$router.push({ path: item.url }); } }3、方案三
使用catch方法捕获router.push异常。
this.$router.push(route).catch(err => { console.log('输出报错', err); });4、方案四
降低路由版本。
卸载原来的版本
npm uninstall vue-router
安装指定版本
npm install vue-router@3.0.65、总结
方案一亲测多次都没有用,最靠谱的是方案四,其他方案没测。
6、相关链接1、解决Vue报错:Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location