Vue-router 报错NavigationDuplicated的解决方法

(编辑:jimmy 日期: 2025/4/20 浏览:2)

版本: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()没有作用。

一句话新闻

Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。