Hey, I'm facing an issue with my app.module setup. I have implemented lazy loading to load the core module and store roles in the core component. Everything works fine when I navigate from one page to another with the role guard applied. However, when I directly type the URL of a page with the role guard, it fails to load the roles. I tried using skipWhile but it didn't solve the issue. Any suggestions on how to resolve this? Thanks!
AppRoutingModule
{
path: '',
children: [{
path: '', loadChildren: () => import('./core/core.module').then(m => m.CoreModule)
}]
},
CoreRoutingModule
{
path: '',
component: CoreComponent,
children: [
{
path: "test,
loadChildren: () => import('@modules/test/test.module').then(m => m.TestModule),
canActivate: [MyGuard]
......
CoreComponent
ngOnInit(): void {
this.authFacade.initAll();
this.authFacade.loginCheck();
}
AuthGuard - only for test
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> {
return this.authFacade.user$.pipe(
skipWhile(user => user === undefined),
take(1),
map(user => {
console.log(user);
if (!user)
return false;
return true;
})
)
}