vue-router3,点击相同的路由,会报错NavigationDuplicated

vue-router点击相同的路由链接会报错NavigationDuplicated

{
    "_name": "NavigationDuplicated",
    "name": "NavigationDuplicated",
    "message": "Navigating to current location (\"/createAvt\") is not allowed"
}

在router文件中添加

import Router from 'vue-router'
// Router 是import导入的路由
// 获取原型对象push函数
const originalPush = Router.prototype.push
// 获取原型对象replace函数
const originalReplace = Router.prototype.replace
// 修改原型对象中的push函数
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
// 修改原型对象中的replace函数
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
}
posted @ 2022-12-21 19:35  jiazq  阅读(113)  评论(0)    收藏  举报