NavigationDuplicated: Avoided redundant navigation to current location: “/xxx“.

错误
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)
}

这样当我们重复点击路由时,就不会报以上错误了!

猜你喜欢

转载自blog.csdn.net/weixin_46351593/article/details/113759515