解决Vue重复路由产生的错误

Vue项目中路由重复

产生如下报错

Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/main/index".
原因:vue-router路由版本更新产生的问题,导致路由跳转失败抛出该错误,但并不影响程序功能

image

解决方法

在 router下的 index.js 中插入如下代码

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

问题解决

posted @ 2022-03-08 22:40  朝颜浅语  阅读(185)  评论(0编辑  收藏  举报