本文主要是介绍解决:vue-router Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
router配置文件中 重写
我是3.5版本 跳转时候引入了 promise
我们看报错可以看到 缺少错误回调
1.直接push/replace 时候添加回调 但是每个路由跳转的地方都要在push/replace中写回调 不如直接原型重写
2.重写push/replace 如下
//存储push
let originPush=VueRouter.prototype.push
let originReplace=VueRouter.prototype.replace//重写
VueRouter.prototype.push=function(location,resole,reject){if(resole&&reject){originPush.call(this,location,resole,reject)}else{originPush.call(this,location,()=>{},()=>{})}
}
VueRouter.prototype.replace=function(location,resole,reject){if(resole&&reject){originReplace.call(this,location,resole,reject)}else{originReplace.call(this,location,()=>{},()=>{})}
}
这篇关于解决:vue-router Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!