2
  path: 'dashboard',
  component: DashboardComponent,
  canActivate: [AuthGuard],
  resolve: {
    userData: UserDataResolver
  },
  children: [
    {
      path: 'manage-users',
      component: ManageUsersComponent,
      canActivate: [ManageUsersGuard],
    },

This is my route, the parent route is dashboard, all child routes have snapshot.data.userData because UserDataResolver gets the data for the user after passing AuthGuard.

ManageUsersGuard needs userData that is resolved by his parent route in order to know whether if you can access that route or not, I don't want to create another API call while I know that I already get that data.

Problem ManageUsersGuard is being activated before the resolver of the parent route, why is that and what is the right approach?

Ben Beri
  • 1,101
  • 4
  • 23
  • 64
  • Add `resolve: {userData: UserDataResolver}` to a parent route. You can use empty routes `{path: '', resolve: {userData: UserDataResolver}, children: [...]}`. You'll find the data in the *parent* of the activated route. – Reactgular Dec 09 '19 at 12:39
  • 1
    You can use `canActivateChild` in `children: [ { path: 'manage-users', component: ManageUsersComponent, canActivateChild: [ManageUsersGuard], }` – Developer Dec 09 '19 at 12:41
  • https://stackoverflow.com/questions/49428112/canactivate-guards-on-child-routes-run-before-parent-resolve-finish – Developer Dec 09 '19 at 12:50

0 Answers0