重复点击路由导致提示避免到当前位置的冗余导航 解决方法

257 阅读1分钟

错误信息

解决方法

路由配置文件添加代码

// 使用push方法跳转路由报错 重复点击路由,导致提示避免到当前位置的冗余导航 解决方法
const routerRePush = VueRouter.prototype.push
VueRouter.prototype.push = function (location) {
  return routerRePush.call(this, location).catch(error => error)
}
// 使用replace方法跳转路由报错 重复点击路由,导致提示避免到当前位置的冗余导航 解决方法
const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
  return originalReplace.call(this, location).catch(err => err)
}