const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
return VueRouterPush.call(this, to).catch(err => err)
}
在router/index.js中加上这行代码
Vue Router 错误处理
本文介绍了一种在 Vue Router 中处理导航错误的方法,通过覆盖默认的 push 方法来捕获并处理可能出现的错误。
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
return VueRouterPush.call(this, to).catch(err => err)
}
在router/index.js中加上这行代码
814
3435
2万+
5367
2030
8132

被折叠的 条评论
为什么被折叠?