Performance: Route parameters with ActivatedRoute
MEDIUM IMPACT
This affects the speed of rendering components that depend on route parameters and the responsiveness of route changes.
readonly id = this.route.params.pipe( map(params => params['id']), distinctUntilChanged() ); // Use async pipe in template: {{ id | async }}
constructor(private route: ActivatedRoute) {
this.route.params.subscribe(params => {
this.loadData(params['id']);
});
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual subscription without operators | Multiple redundant updates | Multiple reflows on each route change | High paint cost due to repeated DOM updates | [X] Bad |
| Using async pipe with distinctUntilChanged | Updates only on parameter change | Single reflow per unique change | Minimal paint cost | [OK] Good |