这个问题困扰很久。
之前有看过一个写法
// const originalPush = Router.prototype.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)
// }
这个写法发现如果改变路由模式 mode 改history 会出问题。
后来仔细研究
permission.js里的next({ ...to, replace: true })会被认为是一个失败的navigation(虽然能导航成功,但不再是原来的to),所以login里的push()返回一个rejected Promise。
解决方案:在push()后面接一个.catch(()=>{})
即: this.$router.push({ path: '/' }, () => {})
Error: Redirected when going from “/login?redirect=%2Fdashboard“ to “/dashboard“ via a navigation
最新推荐文章于 2025-02-05 13:52:10 发布