Interview Questions

1. What do you understand by the RouterState?

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.

@Component({templateUrl:'template.html'})  

class MyComponent {  

  constructor(router: Router) {  

    const state: RouterState = router.routerState;  

    const root: ActivatedRoute = state.root;  

    const child = root.firstChild;  

    const id: Observable<string> = child.params.map(p => p.id);  

    //...  

  }  

}  


By Md Riyazuddin 2 0
Is this helpful? Yes No

Submit an interview question

Submitted questions and answers are subject to review and editing, and may or may not be selected for posting, at the sole discretion of w3Sniff.

Get Started

Comments

Leave a Comment


Check out more interview questions

Based on your skills

MS SQL Server

5344623 1720 188 859

Angular

154869 92 0 46

Wordpress

131092 72 1 36