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内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
使用element+vuedraggable实现图片上传拖拽排序
这篇文章主要为大家详细介绍了使用element+vuedraggable实现图片上传拖拽排序,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2022-04-04
父组件中vuex方法更新state子组件不能及时更新并渲染的完美解决方法
这篇文章主要介绍了父组件中vuex方法更新state子组件不能及时更新并渲染的完美解决方法,需要的朋友可以参考下2018-04-04


最新评论