vue路由报错Avoided redundant navigation

今天在做项目时,测试环境路由正常,本地也是正常,到了过渡环境报错Avoided redundant navigation,大致意思就是避免冗余导航,可能是我要跳转的路由中包含共同的/user,查了几篇博客,由于多数人转载不注明出处,选择时间发布较早的博文作为参考。在这里如果原创作者看到请及时联系我,我将及时更新原创链接(http://www.sunxiaoning.com/language/1076.html)。

 

解决方案:在router文件加下index.js或者router.js中添加如下代码

import Vue from 'vue'
import VueRouter from 'vue-router'

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

Vue.use(VueRouter)