重复点击路由,导致提示避免到当前位置的冗余导航(路由冗余)解决方式


项目中

报错:  NavigationDuplicated: Avoided redundant navigation to current location:

(NavigationDuplicated: 避免了对当前位置的冗余导航)

解决方法:

这个报错的关键是this.$router.push(...).catch(err => err)要有后面的catch。因为跳转方法返回了一个promise对象,要有处理拒绝的方法。

首先检查,路由跳转的时候是不是调用的push方法,还是用的replace

打开 router 文件夹下的 index.js(路由文件)文件中添加如下代码:

//     pust方法

const routerRePush = VueRouter.prototype.push
VueRouter.prototype.push = function (location) {
  return routerRePush.call(this, location).catch(error => error)
}

 

 

 

//     replace 方法
const routerReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function (location) {
  return routerReplace.call(this, location).catch(error => error)
}

 然后重新运行项目,问题解决


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM