Performance: Query parameters and fragments
This affects page load speed and interaction responsiveness by how Angular processes URL changes and updates the view.
this.router.navigate([], { fragment: 'section2', queryParamsHandling: 'preserve' });
this.router.navigate([], { queryParams: { filter: 'new' }, queryParamsHandling: 'merge' });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full queryParams update with navigate() | Multiple DOM updates | 1 reflow per update | High paint cost | [X] Bad |
| Fragment update only with navigate() and fragment option | Minimal DOM changes | 0 reflows | Minimal paint cost | [OK] Good |
navigate with an array for the path and an options object.queryParams, not params or query.this.route.queryParams.subscribe(params => console.log(params['page']))
this.router.navigate(['/items'], { queryParams: { page: 3 } })this.route.fragment.subscribe(fragment => {
console.log(fragment.toUpperCase())
}){ tab: 'settings' } and fragment 'section2'. Which code correctly does this in Angular?queryParams for query parameters and fragment for URL fragment.queryParams and fragment. Others use incorrect keys like params, query, or hash.Pass the test and this pattern moves unknown