angular 9 why canActivateChild start befor canActivate completed?

92 Views Asked by At

in my program I have a func in canActivateChild that need to occur after canActivate finished , but the child component loads befor canActivate of the parent finish,why?

my routing-module:
const routes: Routes = [

    {
    path: '',
    component: MainComponent,
    canActivate: [LoadDataGuard, ConfigureJsGuard],
    canActivateChild: [EnterChildGuard],
    canDeactivate: [CleanupJsGuard],
    data: {
        modelService: ModelService,
     
    } ,
    children: [
        {
            component: ChildComponent,
         .......
1

There are 1 best solutions below

0
On

you can add canActivateChild to empty path child of main route

like

{
path: '',
component: MainComponent,
canActivate: [LoadDataGuard, ConfigureJsGuard],
canDeactivate: [CleanupJsGuard],
data: {
    modelService: ModelService,
 
} ,
children: [
    path: '',
    canActivateChild: [EnterChildGuard],
    children: [
    {
        component: ChildComponent,
      .......
      },
    ]