Reputation: 4671
I'm trying to use Angular2 to lazy load some modules. I could make it work, but when I use it with canActivateChild, it blocks the navigation but load the module, I don't know if I need to do anything else, but I'd like to load the module only if I'm enable to access the route. For example, this is an admin dashboard and I want to load the AdminModule only when the user is logged.
This is my main module routing:
export const routing = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
{
path: '',
canActivateChild: [AuthGuard],
children: [
{ path: 'home', component: HomeComponent },
{ path: 'adm', loadChildren: './admin/admin.module#AdminModule' },
]
},
{ path: '**', component: NotFoundComponent },
];
And this is my admin routing:
export const adminRouting = [
{ path: '',
children: [
{ path: 'client', component: ClientComponent },
{ path: 'support', component: SupportComponent },
// more routes
]
},
];
Like I said, everything in the navigation is working as expect, but when I'm not logged I wanted to prevent the lazyLoad module to be loaded.
Upvotes: 3
Views: 1946
Reputation: 1523
According to the routing guide on angular I believe you have to use canLoad
instead of canActivate
.
Upvotes: 2