关于javascript:Avoided-redundant-navigation-to-current-location

12次阅读

共计 519 个字符,预计需要花费 2 分钟才能阅读完成。

在 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);

正文完
 0