VUE Router路由跳转报错:vue-router.esm.js?fe87:2051 Uncaught (in promise) NavigationDuplicated {_name: "Nav

背景:

this.$router.push({path: "path"}) , 跳转时出现错误.

完整错误:

vue-router.esm.js?fe87:2051 Uncaught (in promise) NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated", message: "Navigating to current location ("/nitrogenActual") is not allowed", stack: "Error↵    at new NavigationDuplicated (webpack-int…al:///./node_modules/vue/dist/vue.esm.js:1862:26)"}

解决办法:

在定义路由的js下添加下面的代码,记得修改路由名字Router(使用自己定义的名字)

/**
*	源码 install 安装依赖时,Router(路由版本不一致)
*	也可以修改 package.json 里面的 Router 版本
*/
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

 

你可能感兴趣的:(VUE.JS)