重写路由push方法,将以下代码复制到路由index.js里面
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
这段代码展示了如何在VueRouter中重写原型上的push方法,以确保在调用push函数时,任何抛出的错误都能被正确捕获并处理。通过这种方式,开发者可以更好地控制路由切换时的异常情况。
重写路由push方法,将以下代码复制到路由index.js里面
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
1825
999
3349
751

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