0

I've got a simple guard on my admin area

{
    path: 'admin',
    canLoad: [AuthGuard, AccountGuard],
    loadChildren: () =>
      import('./features/admin/admin.module').then((m) => m.AdminModule),
    data: { preload: false }
  },

It works nice the first time I do login but if I do logout and than login again it doesn't work so I ended up with

{
    path: 'admin',
    canLoad: [AuthGuard, AccountGuard],
    canActivate: [AuthGuard, AccountGuard],
    loadChildren: () =>
      import('./features/admin/admin.module').then((m) => m.AdminModule),
    data: { preload: false }
  },

I'm wondering is there a better way?

user3887366
  • 2,226
  • 4
  • 28
  • 41

1 Answers1

0

You can use CanLoad for the parent routes and CanActivate for lazy-loaded children. Because CanActivate will load the module anyway, no matter true or false was returned it's no sense to use it at the same time with CanLoad for the parent route, in that case, CanLoad does not give any effect. So try to use CanActivate for child routes only and CanLoad for parent route.

Yaroslav
  • 358
  • 3
  • 14