I
I
iluxa18102019-05-17 13:41:18
Angular
iluxa1810, 2019-05-17 13:41:18

Why does the child CanActivate fire before the root Resolver?

In general, there is such a configuration:

const appRoutes: Routes = [
  {
    path: '', component: BaseComponent, resolve: { data: PermissionResolver }, children: [
      {
        path: '', loadChildren: './area/Home/Home.module#HomeModule',
      }
}

Inside the Home module, this is the route:
const homeRoutes: Routes = [
  { path: '', redirectTo: '/home', pathMatch: 'full' },
  {
    path: 'home', component: homeContainerComponent, children: [
      {
        path: 'add', component: AddContainerComponent, canActivate: [CanActivateAdd], children: [
          {
            path: '', component: AddComponent
          }
        ]
      }
    ],
  }
];

So, when I immediately go to home / add through the address bar, then Resolve does not work, but canActive immediately works.
In general, I expected Guards to fire in a hierarchical order.
That is, first Resolve, since it hangs in the root route, and then all child Guards.
How to achieve what you want? That is, first get the credentials from the API, regardless of where the user has logged in, and then use canActive?
I found only such an article, how canActive is made from a resolver. Really there are no methods "from a box"?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question