vue点击跳转同一路由报错,解决办法

2,226 阅读1分钟
  • vue路由报错
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/liveBastDou".
  • 原因:多次点击跳转同一路由是不被允许的
  • 解决办法:在router.js文件里加上如下代码即可
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this,location).catch(err => err)
}

const VueRouterReplace = Router.prototype.replace
Router.prototype.replace = function replace (to) {
  return VueRouterReplace.call(this, to).catch(err => err)
}

参考: blog.csdn.net/qq_30071415…