Performance: Router outlet for view rendering
This affects how quickly the main content appears and how smoothly navigation between views happens.
Use a single <router-outlet></router-outlet> with lazy-loaded feature modules and minimal nested outlets.
In the main component template: <router-outlet></router-outlet> with many nested router outlets and heavy components loaded eagerly.
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eager loading many nested router outlets | High (many nodes added at once) | Multiple reflows per route change | High paint cost due to large DOM | [X] Bad |
| Single router outlet with lazy-loaded modules | Low (only active view nodes) | Single reflow per route change | Low paint cost with smaller DOM | [OK] Good |
<router-outlet> element in an Angular application?<router-outlet><router-outlet>.<router-outlet> is a tag that must be opened and closed properly in HTML.<router-outlet> to have both opening and closing tags; self-closing is invalid here.<router-outlet /><routerOutlet>const routes = [
{ path: 'home', component: HomeComponent },
{ path: 'about', component: AboutComponent }
];
Template:
<router-outlet></router-outlet>HomeComponent.<router-outlet> displays the matched component's template, so HomeComponent content appears.<router-outlet></router-outlet> <router-outlet></router-outlet>What problem will this cause when navigating routes?
<router-outlet> present in the template.<router-outlet> must have a unique name attribute.Pass the test and this pattern moves unknown