List out the differences between ActivatedRoute and RouterState, with reference to Angular 2.

devquora
devquora

Posted On: Feb 22, 2018

 

    1 Answer Written

  •  devquora
    Answered by Mayank Sambharwal

    Difference between activatedroute and routerstate

    RouterState is an interface which represents the state of the router as a tree of activated routes. Every node of this tree knows about the "consumed" URL segments, the extracted parameters, and the resolved data.

    RouterState Interface looks like:

     
    interface RouterState extends Tree {
      snapshot: RouterStateSnapshot
      toString(): string
    }
    

    ActivatedRoute interface provides access to information about a route associated with a component that is loaded in an outlet. Use to traverse the RouterState tree and extract information from nodes.

    ActivatedRoute Interface looks like

    interface ActivatedRoute {
      snapshot: ActivatedRouteSnapshot
      url: Observable<UrlSegment[]>
      params: Observable
      queryParams: Observable
      fragment: Observable
      data: Observable
      outlet: string
      component: Type | string | null
      routeConfig: Route | null
      root: ActivatedRoute
      parent: ActivatedRoute | null
      firstChild: ActivatedRoute | null
      children: ActivatedRoute[]
      pathFromRoot: ActivatedRoute[]
      paramMap: Observable
      queryParamMap: Observable
      toString(): string
    }
    

Related Questions

Please Login or Register to leave a response.

Related Questions

Angular 2 Interview Questions

What is Angular 2 ?

Angular 2 is a completely revived component-based framework in which an application is a tree of loosely coupled compon..

Angular 2 Interview Questions

List some advantages of Angular 2 over Angular1.

Angular 2 is a re-written version of Angular1 and not an update. The best way to compare Angular 2 and Angular 1 is by f..

Angular 2 Interview Questions

What are the new features of Angular 2?

Angular 2 is a platform that encompasses a wide range of capabilities. Some new features were added in Angular 2 which i..