使用编程时导航出现的错误: Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location 的解决方案

重写VueRouter实例的push和replace方法:

push方法重写的实现代码:

 1 // 保存原来的push方法
 2 const  originPush = VueRouter.prototype.push;
 3 
 4 VueRouter.prototype.push = function(location,resolve,reject){
 5     if(resolve && reject){
 6         originPush.call(this,location,resolve,reject)
 7     } else{
 8         originPush.call(this,location,() =>{},()=> {})
 9     }
10 }  

replace方法重写的实现代码:

1 // 保存原来的replace方法
 2 const  originReplace = VueRouter.prototype.replace;
 3 
 4 VueRouter.prototype.replace= function(location,resolve,reject){
 5     if(resolve && reject){
 6         originReplace.call(this,location,resolve,reject)
 7     } else{
 8         originReplace.call(this,location,() =>{},()=> {})
 9     }
10 } 

 

posted @ 2021-12-28 17:01  我只拥你  阅读(113)  评论(0)    收藏  举报