Vue.js:router出現 message: “Navigating to current location (XXX) is not allowed”

印象是在設定使用者未登入,就導回首頁跳出以下錯誤

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

解決辦法為在router.js裡加入

const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}

就不會再跳錯

來源:解决vue项目路由出现message: “Navigating to current location (XXX) is not allowed”的问题