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

RouterStateSnapshot

npm Package @angular/router
Module import { RouterStateSnapshot } from '@angular/router';
Source router/src/router_state.ts

Represents the state of the router at a moment in time.

Interface Overview

      
      interface RouterStateSnapshot extends Tree { 
  url: string
  toString(): string
}
    

How To Use

      
      @Component({templateUrl:'template.html'})
class MyComponent {
  constructor(router: Router) {
    const state: RouterState = router.routerState;
    const snapshot: RouterStateSnapshot = state.snapshot;
    const root: ActivatedRouteSnapshot = snapshot.root;
    const child = root.firstChild;
    const id: Observable<string> = child.params.map(p => p.id);
    //...
  }
}
    

Description

RouterStateSnapshot is a tree of activated route snapshots. Every node in this tree knows about the "consumed" URL segments, the extracted parameters, and the resolved data.

Members

      
      url: string
    

The url from which this snapshot was created


      
      toString(): string