錯誤代碼:
1 NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated",
message: "Navigating to current location ("/index") is not allowed",
stack: "Error↵ at new NavigationDuplicated (webpack-int…e_modules/element-ui/lib/mixins/emitter.js:29:22)"}
操作:
在VUE項目中點擊兩次路由切換
原因:
在路由跳轉的時候同一個路由多次添加
是不被允許的
解決方案(兩種):
1.切換版本回3.0版本
2.在你引了vue-router
的js文件里加上如下代碼即可
import Vue from 'vue' //如果已引用,不需要重復引用 import Router from 'vue-router'; //如果已引用,不需要重復引用 Vue.use(Router) //如果已引用,不需要重復引用 const VueRouterPush = Router.prototype.push Router.prototype.push = function push (to) { return VueRouterPush.call(this, to).catch(err => err) }