解決vue項目路由出現message: "Navigating to current location (xxxx) is not allowed"的問題

出現的錯誤:在這裏插入圖片描述
出現這個錯誤的原因是,在路由跳轉的時候兩次push的path地址相同

解決方法兩種:

1.切換版本回3.0版本

2.在你引了vue-router的js文件里加上如下代碼即可

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