ElementUI报重复点击菜单错误,解决方案,亲测有效!

重复点击菜单报错误代码如下:
Error: Avoided redundant navigation to current location: “/users”.
at createRouterError (vue-router.esm.js?8c4f:2062)
at createNavigationDuplicatedError (vue-router.esm.js?8c4f:2035)
at HashHistory.confirmTransition (vue-router.esm.js?8c4f:2195)
at HashHistory.transitionTo (vue-router.esm.js?8c4f:2125)
at HashHistory.push (vue-router.esm.js?8c4f:2595)
at VueRouter.push (vue-router.esm.js?8c4f:2916)
at VueComponent.routeToItem (menu.js?443e:796)
at VueComponent.handleItemClick (menu.js?443e:763)
at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
at VueComponent.Vue.$emit (vue.runtime.esm.js?2b0e:3888)
在这里插入图片描述
对于有代码洁癖的人来说,眼里是容不得半点报红的
以下是我提供的解决方案,亲测有效
在自己的router.js,或者是index.js(全局路由配置的地方)在最底部加上代码如下
1.如果没有创建VueRouter时加上以下代码
需要注意一点

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

如果已经创建了Router 则按照自己定义的名字添加以下代码
在这里插入图片描述

const originalPush = router.push
   router.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}

以上就是我解决方案的方法,如有疑问,请下方联系或者私信博主!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值