-
在
Vue-router≥3.0
版本中,路由回調形式已經改成了Promise API
形式,返回一個Promise
。 -
在相同路由轉跳並且沒有捕獲錯誤時會在控制打印如下信息:
-
方法1:可在全局配置一個
catch
捕捉錯誤:我是直接寫在
router > index.js
文件中// 包裝路由函數,添加處理錯誤方法; const originalPush = VueRouter.prototype.push; VueRouter.prototype.push = function(location) { return originalPush.call(this, location).catch(err => err); };
-
方法2:在調用路由函數時捕獲錯誤:
-
方法3:使用3.0以下版本。