Vue: Redirected when going from “x“ to “x“ via a navigation guard
@vue/cli 4.3.1
vue-router: ^3.3.2
使用路由重定向做了登錄驗證后, 報錯
Error: Redirected from “/login” to “/index” via a navigation guard.
解決方案:
1. 刪除node_modules酒甸,到package.json中將vue-router改為 3.0.7 延塑,重新npm i(未測試)
2. 在 route.js 下粘貼一下代碼 (使用中)
// 解決Vue-Router升級導(dǎo)致的Uncaught(in promise) navigation guard問題
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
? if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
? return originalPush.call(this, location).catch(err => err)
}
?參考資料:
https://forum.vuejs.org/t/topic/97260
https://www.cnblogs.com/pjw233/p/12658849.html