Is it possible to have multiple loadChildrens in a router?

I am using the final release of angular 2 and have seen a great lazy load function with loadChildren.

Minimal example

export const routes: Routes = [ { path: 'crisis', loadChildren: 'app/crisis/crisis.module#CrisisModule' } ]; 

In this case, the .module crisis loads lazily, but its string, not the array. But my page could exist with several components in several modules, so I wonder:

Can you be lazy to load several modules without creating specifically for this route that contains components?

+5
source share
1 answer

I ran into the same problem as you, and I found a solution. Hope this helps others. You can just do something like this

 const routes: Routes = [ { path: '', component: DashboardComponent, children: [ { path: 'events', loadChildren: './event/event.module#EventModule' }, { path: 'participants', loadChildren: './participant/participant.module#ParticipantModule' } ] } ]; 

And, of course, in your parent component (here DashbordComponent) you will need to put a router-outlet .

0
source

Source: https://habr.com/ru/post/1259085/


All Articles