vue报错“NavigationDuplicat: Avoided redundant navigation to current location”解决方法
方法1查看自己的vue-router版本,如果在在3.0版本以上,将其改为3.0版本。方法2修改push源码,在router下的index.js文件中添加下列代码即可。// 解决vue-router在3.0版本以上重复报错问题const originalPush = VueRouter.prototype.pushVueRouter.prototype.push = function push(l
·
当使用this.$router.push
或this.$router.repalce
指令时报错“NavigationDuplicat: Avoided redundant navigation to current location“,即路由重复,主要是vue-router版本问题,有方法说将版本变为3.0,我尝试之后这种方法无效,经过尝试,以下两种方法有效。
方法1
在使用的指令后面加上.catch(err => err)
,即
this.$router.push(this.path).catch(err => err)
this.$router.replace(this.path).catch(err => err)
这种方法,需要在每次使用指令时都需要添加.catch(err => err)
。
方法2
修改push源码,在router下的index.js文件中添加下列代码即可。
// 解决vue-router在3.0版本以上重复报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
这种方法,只需要修改一次源码,使用指令时无需再添加.catch(err => err)
https://blog.csdn.net/weixin_43242112/article/details/107595460
https://www.cnblogs.com/yequxue/p/13255945.html
更多推荐
已为社区贡献1条内容
所有评论(0)