This is the archived documentation for Angular v6. Please visit angular.io to see documentation for the current version of Angular.

RouterState

Represents the state of the router.

See more...

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

Description

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.

Properties

Property Description
snapshot: RouterStateSnapshot

The current snapshot of the router state

Methods

toString(): string
      
      toString(): string
    

Parameters

There are no parameters.

Returns

string

Usage notes

Example

@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); //... } }
      
      @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);
    //...
  }
}
    

See ActivatedRoute for more information.