Vue Router路由守卫beforeEach的next方法使用?-灵析社区

半寸时光爱思考

Vue Router路由守卫函数beforeEach(to,from,next)里的next方法能否写在Promisse的回调函数than里面?

阅读量:153

点赞量:0

问AI
可以 router.beforeEach(async(to, from, next) => { if (to.meta.auth) { // need verification // This is a promise function 👇 await widget.user .authVerification() .then(() => { next(); }) .catch((error) => { // Session expired console.log(error); next("/login"); }); } }