假设我想在 vue-router 中创建一个 AuthService 来验证当前会话,然后再继续下一个路由,如下例所示:
http://vuejs.github.io/vue-router/en/api/before-each.html
router.beforeEach(function ({ to, next }) {
if (to.path === '/auth-required') {
// return a Promise that resolves to true or false
return AuthService.isLoggedIn()
} else {
next()
}
})
Run Code Online (Sandbox Code Playgroud)
我在网上搜索了很多,但从未见过任何尝试在不使用 JWT 的情况下使用 vue-router 验证会话。