vue專案重複點選同一標籤路由報錯

Lmosine發表於2020-11-20

首先確定點選觸發的函式是 push 還是 replace,然後重寫其對應的方法

push

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const originalReplace = Router.prototype.replace
Router.prototype.push = function push(location) {
  return originalReplace.call(this, location).catch(err => err)
}

let router = new Router()

replace

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const originalReplace = Router.prototype.replace
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
}

let router = new Router()

相關文章