Avoided redundant navigation to current location
文章目录
在Vue项目中遇到了这个错误,不影响功能,但是控制台会在push的时候报这个错:
vue-router.esm.js?fe87:1958 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/Home".在网上找了半天,几乎都是说Vue-router的版本问题,要么重载更低的版本,要么在main.js中加以下代码:
const originalPush = Router.prototype.push Router.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err) }
但是我试了半天并无用,我的控制台报了push不存在的语法错误,编译无法通过,可能只有我不能用这种解决方式。
本次解决方案:
因为我的项目中只有一处push了首页,只需要捕获push的异常便可以了(replace也同样)。
//设置首页默认显示
this.$router.push('/Home').catch(err=>err);
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论