如何解决Vue-router中NavigationDuplicated错误问题?

更新于
2026-09-25 09:08:17
1阅读来源:SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计265个文字,预计阅读时间需要2分钟。

如何解决Vue-router中NavigationDuplicated错误问题?

版本:3.1.x错误原因:使用 push()、replace() 进行导航时,不能重复导航到当前路由。解决方法:方法1:在定义路由的文件中(router/index.js)javascriptconst originalPush=VueRouter.prototype.push;VueRouter.prototype.push=function (location, resolve, reject) { if (this.isCurrentRoute(location)) return; originalPush.call(this, location, resolve, reject);};

版本:3.1.x

报错原因:

如何解决Vue-router中NavigationDuplicated错误问题?

使用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内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

本文共计265个文字,预计阅读时间需要2分钟。

如何解决Vue-router中NavigationDuplicated错误问题?

版本:3.1.x错误原因:使用 push()、replace() 进行导航时,不能重复导航到当前路由。解决方法:方法1:在定义路由的文件中(router/index.js)javascriptconst originalPush=VueRouter.prototype.push;VueRouter.prototype.push=function (location, resolve, reject) { if (this.isCurrentRoute(location)) return; originalPush.call(this, location, resolve, reject);};

版本:3.1.x

报错原因:

如何解决Vue-router中NavigationDuplicated错误问题?

使用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内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!