在項目開發(fā)過程中,當用戶重復點擊相同菜單的時候可能會報:Error: Avoided redundant navigation to current location: "your route url"
的錯誤捍歪,要解決該報錯诡壁,需要在路由配置的index.js
中寫入以下代碼顷级。
import VueRouter from 'vue-router'
Vue.use(VueRouter)
// 解決重復點擊相同路由報錯
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
這樣點擊后就不會出現(xiàn)以上的報錯了麦萤。