Uncaught (in promise) Error: Navigation cancelled from “/” to “/login” with a new navigation.
這個錯誤是vue-router內部錯誤,沒有進行catch處理,導致的編程式導航跳轉問題,往同一地址跳轉時會報錯的情況。
push和replace 都會導致這個情況的發生。

解決方法如下:
在路由器中進行配置:router/index.js
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
// 解決報錯
const originalPush = Router.prototype.push
const originalReplace = Router.prototype.replace
// push
Router.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)
}
// replace
Router.prototype.replace = function push (location, onResolve, onReject) {
if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
return originalReplace.call(this, location).catch(err => err)
}
僅在此記錄一下遇到的問題和最后的解決辦法,親測可用。
