Performance: Defining routes array
MEDIUM IMPACT
This affects the initial page load speed and navigation responsiveness by controlling how Angular matches URLs to components.
const routes = [ { path: '', component: HomeComponent }, { path: 'dashboard', loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule) }, { path: 'profile', component: ProfileComponent }, { path: '**', component: NotFoundComponent } ];
const routes = [ { path: '', component: HomeComponent }, { path: 'dashboard', component: DashboardComponent, children: [ { path: 'stats', component: StatsComponent }, { path: 'reports', component: ReportsComponent }, { path: 'settings', component: SettingsComponent } ]}, { path: 'profile', component: ProfileComponent }, { path: '**', component: NotFoundComponent } ];
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Flat routes with lazy loading | Minimal DOM until route activates | Single reflow on route change | Low paint cost due to smaller initial bundle | [OK] Good |
| Deeply nested routes array | More DOM nodes initialized upfront | Multiple reflows during navigation | Higher paint cost due to larger bundle | [X] Bad |