Credit to devdocs.io

angular 2.0_typescript

angular

ActivatedRoute

Stable Interface

What it does

Contains the information about a route associated with a component loaded in an outlet. ActivatedRoute can also be used to traverse the router state tree.

How to use

@Component({templateUrl:'./my-component.html'})
class MyComponent {
  constructor(route: ActivatedRoute) {
    const id: Observable<string> = route.params.map(p => p.id);
    const url: Observable<string> = route.url.map(s => s.join(''));
    const user = route.data.map(d => d.user); //includes `data` and `resolve`
  }
}

Interface Overview

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

Interface Description

Interface Details

snapshot : ActivatedRouteSnapshot

The current snapshot of this route.

url : Observable<UrlSegment[]>

The URL segments matched by this route. The observable will emit a new value when the array of segments changes.

params : Observable<Params>

The matrix parameters scoped to this route. The observable will emit a new value when the set of the parameters changes.

queryParams : Observable<Params>

The query parameters shared by all the routes. The observable will emit a new value when the set of the parameters changes.

fragment : Observable<string>

The URL fragment shared by all the routes. The observable will emit a new value when the URL fragment changes.

data : Observable<Data>

The static and resolved data of this route. The observable will emit a new value when any of the resolvers returns a new object.

outlet : string

The outlet name of the route. It's a constant.

component : Type<any>|string

The component of the route. It's a constant.

routeConfig : Route

The configuration used to match this route.

root : ActivatedRoute

The root of the router state.

parent : ActivatedRoute

The parent of this route in the router state tree.

firstChild : ActivatedRoute

The first child of this route in the router state tree.

children : ActivatedRoute[]

The children of this route in the router state tree.

pathFromRoot : ActivatedRoute[]

The path from the root of the router state tree to this route.

toString() : string

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

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