Navigation Guards
Zova provides a module home-base, in which navigation guards can be added, such as checking the user's authentication status, redirecting to the Login page, and so on
onRouterGuards
The module home-base provides a Service bean ServiceRouterGuards, and you can directly add custom logic in the onRouterGuards method
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