vue报错“NavigationDuplicat: Avoided redundant navigation to current location”解决方法

当使用this.$router.pushthis.$router.repalce指令时报错“NavigationDuplicat: Avoided redundant navigation to current location“,即路由重复,主要是vue-router版本问题,有方法说将版本变为3.0,我尝试之后这种方法无效,经过尝试,以下两种方法有效。

方法1

在使用的指令后面加上.catch(err => err),即

this.$router.push(this.path).catch(err => err)
this.$router.replace(this.path).catch(err => err)

这种方法,需要在每次使用指令时都需要添加.catch(err => err)

方法2

修改push源码,在router下的index.js文件中添加下列代码即可。

// 解决vue-router在3.0版本以上重复报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

这种方法,只需要修改一次源码,使用指令时无需再添加.catch(err => err)

https://blog.csdn.net/weixin_43242112/article/details/107595460
https://www.cnblogs.com/yequxue/p/13255945.html

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值