Vue项目中路由重复
产生如下报错
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “/main/index”.
原因:vue-router路由版本更新产生的问题,导致路由跳转失败抛出该错误,但并不影响程序功能
解决方法
在 router下的 index.js 中插入如下代码
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch((err) => err)
}