重復點擊路由,導致提示避免到當前位置的冗余導航(路由冗余)解決方式


項目中

報錯:  NavigationDuplicated: Avoided redundant navigation to current location:

(NavigationDuplicated: 避免了對當前位置的冗余導航)

解決方法:

這個報錯的關鍵是this.$router.push(...).catch(err => err)要有后面的catch。因為跳轉方法返回了一個promise對象,要有處理拒絕的方法。

首先檢查,路由跳轉的時候是不是調用的push方法,還是用的replace

打開 router 文件夾下的 index.js(路由文件)文件中添加如下代碼:

//     pust方法

const routerRePush = VueRouter.prototype.push
VueRouter.prototype.push = function (location) {
  return routerRePush.call(this, location).catch(error => error)
}

 

 

 

//     replace 方法
const routerReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function (location) {
  return routerReplace.call(this, location).catch(error => error)
}

 然后重新運行項目,問題解決


免責聲明!

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



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