W3cubDocs

/Angular 4 TypeScript

RouterStateSnapshot

Stable Interface

What it does

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

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

Interface Overview

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

Interface 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.

Interface Details

url : string

The url from which this snapshot was created

toString() : string

exported from router/index, defined in router/src/router_state.ts

© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/docs/ts/latest/api/router/index/RouterStateSnapshot-interface.html