Performance: Child routes and nested routing
MEDIUM IMPACT
This affects page load speed and rendering performance by controlling how much of the UI and components load initially versus on demand.
const routes = [ { path: 'parent', component: ParentComponent, children: [ { path: 'child1', loadChildren: () => import('./child1/child1.module').then(m => m.Child1Module) }, { path: 'child2', loadChildren: () => import('./child2/child2.module').then(m => m.Child2Module) } ]} ];
const routes = [ { path: 'parent', component: ParentComponent, children: [ { path: 'child1', component: Child1Component }, { path: 'child2', component: Child2Component } ]} ];
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eager loading child routes | More DOM nodes initially | Multiple reflows if many nested components | Higher paint cost due to large initial render | [X] Bad |
| Lazy loading child routes | Fewer DOM nodes initially | Single reflow on navigation to child | Lower paint cost initially, deferred cost on navigation | [OK] Good |