导航守卫
Zova 提供了一个模块home-base,可以在这个模块中添加导航守卫,比如判断用户认证状态,跳转 Login 页面,等等
onRouterGuards
模块home-base提供了一个 Service bean ServiceRouterGuards,直接在onRouterGuards方法中添加自定义逻辑即可
src/suite/a-home/modules/home-base/src/service/routerGuards.ts
typescript
class ServiceRouterGuards {
protected onRouterGuards(router: BeanRouter) {
router.beforeEach(async to => {
if (to.meta.requiresAuth !== false && !this.$passport.isAuthenticated) {
const [_res, err] = await catchError(() => {
return this.$passport.ensurePassport();
});
if (err) {
this.$errorHandler(err, 'onRouterGuards');
return false;
}
if (!this.$passport.isAuthenticated) {
this.app.$gotoLogin(to.fullPath);
return false;
}
}
});
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19