修复Uncaught (in promise) Error: Redirected when going from “/x“ to “/y“ via a navigation guard.

路由守卫重复进入两次,报错(虽然页面还可以运行)

看网上有很多都试了,感觉都没什么用,后来找了一个,有效,分享一下。
Vue 重复进入相同路由消除警报:

注意:是写在路由的文件中,Vue.use(VueRouter)之上

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