vue-router.esm.js?8c4f:2065 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/cart".
今天在写导航切换页面的时候遇到了这个问题,因为 首页切换按钮本身在App页面上,即路由地址为’ /cart ’ 的页面,重定向到的页面依然是cart页面,也就是所谓的产生了冗余导航,vue-router便报错了。
解决办法 1 :
将如下代码 重写push方法 加入到路由设置文件index.js中即可:
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
解决办法 2 :
将 重定向 放到 末尾