如何解决vue-router报Avoided redundant navigation to current location 错误?

我们在用 vue-router 做单页应用的时候重复点击一个跳转的路由会出现报错,简称路由重复,如下图:

如何解决 vue-router 报 Avoided redundant navigation to current location 错误?

上图的报错就是重复路由引起的,如何解决 vue-router 报 Avoided redundant navigation to current location 路由重复错误呢?

只需在注册路由组建后重写路由就可以,具体代码如下:

// 解决 ElementUI 导航栏中的 vue-router 在 3.0 版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location:any) {
  return originalPush.call(this, location).catch((err:any) => err)
}

如何解决 vue-router 报 Avoided redundant navigation to current location 路由重复错误呢?

「点点赞赏,手留余香」

0

给作者打赏,鼓励TA抓紧创作!

微信微信 支付宝支付宝

还没有人赞赏,快来当第一个赞赏的人吧!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
码云笔记 » 如何解决vue-router报Avoided redundant navigation to current location 错误?

发表回复