解決vue-router路由跳轉的問題 message: "Navigating to current location ("/homePage") is not allowed",警告的問題


錯誤代碼:

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)
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM