We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
升级了vue-router v3.1.6,加了路由守卫,判断没有携带token就指向登录页,强迫症患者看着控制台打出了一堆Uncaught (in promise) undefined十分难受。
v3.1.6
Uncaught (in promise) undefined
在vue-router v3.0.7之后push和replace返回的是promise不是回调,如果遇到路由守卫的next指定到某个页面(例如登录页面),需要主动catch这个promise的reject。[issue2881] (vuejs/vue-router#2881 (comment)) 里posva给出了比较详细的回答和解决方案。
v3.0.7
catch
promise
reject
this.$router.push({ name: `${name}` }, () => {}) // or this.$router.push({ name: `${name}` }, onComplete => { console.log('完成') }, onAbort => { console.log('哦打断了') })
const originalPush = VueRouter.prototype.push VueRouter.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) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
背景
升级了vue-router
v3.1.6
,加了路由守卫,判断没有携带token就指向登录页,强迫症患者看着控制台打出了一堆Uncaught (in promise) undefined
十分难受。原因
在vue-router
v3.0.7
之后push和replace返回的是promise不是回调,如果遇到路由守卫的next指定到某个页面(例如登录页面),需要主动catch
这个promise
的reject
。[issue2881] (vuejs/vue-router#2881 (comment)) 里posva给出了比较详细的回答和解决方案。处理方案
The text was updated successfully, but these errors were encountered: