‘canLoad‘ guard can decide whether a lazy load module can be loaded or not.
@Injectable()
export class CanLoadPokemon implements CanLoad { constructor(private authService: AuthService) { } canLoad(route: Route): Observable<boolean>|Promise<boolean>|boolean { return this.authService.isAuth; } }
app.routers.ts:
{path: ‘home‘, loadChildren: ‘app/home/home.module‘, data: {title: ‘Pokemon List‘}, canLoad: [CanLoadPokemon]},
So if user not login, app won‘t load home module.
时间: 2024-10-12 12:29:40