解決vue項目雙擊路由導航報錯 "Navigating to current location (XXX) is not allowed"

雙擊或者連續點擊路由導航的時候,發現報錯:

"Navigating to current location (XXX) is not allowed"

原因是:在路由裏面添加了相同的路由
解決方案是:
我們可以重寫路由的push方法
在src/router/index.js 裏面import Router from 'vue-router’下
寫入下面方法即可

/**
 * 重寫路由的push方法
 */
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章