错误:
NavigationDuplicated: Avoided redundant navigation to current location: “/xxx”.
原因:
避免到当前位置的冗余导航,是指路由重复。
虽然对项目没有太大影响,但是看到红字十分影响心情。
解决方法:
在router文件夹下的index.js文件中添加如下代码:
// 获取原型对象中的push方法
const originalPush = VueRouter.prototype.push
// 修改原型对象中的push方法
VueRouter.prototype.push = function push (location) {
return originalPush.call(this, location).catch(err => err)
}
// 获取原型对象中的replace方法
const originalReplace = VueRouter.prototype.replace
// 修改原型对象中的replace方法
VueRouter.prototype.replace = function replace (location) {
return originalReplace.call(this, location).catch(err => err)
}
这样当我们重复点击路由时,就不会报以上错误了!