在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);
发表回复