0 votes
in Angular by
What do you understand by the RouterState?

1 Answer

0 votes
by

The RouterState is a tree of activated routes. Every node in this tree knows about the "consumed" URL segments, the extracted parameters, and the resolved data. We can access the current RouterState from anywhere in the application by using the Router service and the routerState property.

  1. @Component({templateUrl:'template.html'})  
  2. class MyComponent {  
  3.   constructor(router: Router) {  
  4.     const state: RouterState = router.routerState;  
  5.     const root: ActivatedRoute = state.root;  
  6.     const child = root.firstChild;  
  7.     const id: Observable<string> = child.params.map(p => p.id);  
  8.     //...  
  9.   }  
  10. }  

Related questions

0 votes
asked Jun 5, 2022 in Angular by Robindeniel
0 votes
asked Jan 15, 2020 in Angular by rahuljain1
...