Vue-router 報錯NavigationDuplicated的解決方法
更新時間:2020年03月31日 15:12:50 作者:lavender
這篇文章主要介紹了Vue-router 報錯NavigationDuplicated的解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
版本:3.1.x

報錯原因:
使用push()、replace()進行導航時,不能重復導航到當前路由。
解決辦法:
方法1:在定義路由的文件中router/index.js
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.repalce = function replace (location) {
return originalReplace.call(this, location).catch(err => err)
}
方法2:在調用push()、replace()方法時,catch
this.$router .replace(this.path) .catch(err => err)
說明:第一種方法好像對replace()沒有作用。
到此這篇關于Vue-router 報錯NavigationDuplicated的解決方法的文章就介紹到這了,更多相關Vue-router 報錯NavigationDuplicated內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
使用element+vuedraggable實現圖片上傳拖拽排序
這篇文章主要為大家詳細介紹了使用element+vuedraggable實現圖片上傳拖拽排序,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04
父組件中vuex方法更新state子組件不能及時更新并渲染的完美解決方法
這篇文章主要介紹了父組件中vuex方法更新state子組件不能及時更新并渲染的完美解決方法,需要的朋友可以參考下2018-04-04

