Vue-router 报错NavigationDuplicated Vue-router 报错NavigationDuplicated的解决办法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Vue-router 报错NavigationDuplicated Vue-router 报错NavigationDuplicated的解决办法

lavender   2021-04-21 我要评论

版本:3.1.x

报错原因:

使用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()没有作用。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们