项目中

报错:  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)
}

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

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/tccg/p/15136388.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!