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

ActivatedRoute

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

See more...

      
      
  1. interface ActivatedRoute {
  2. snapshot: ActivatedRouteSnapshot
  3. url: Observable<UrlSegment[]>
  4. params: Observable<Params>
  5. queryParams: Observable<Params>
  6. fragment: Observable<string>
  7. data: Observable<Data>
  8. outlet: string
  9. component: Type<any> | string | null
  10. routeConfig: Route | null
  11. root: ActivatedRoute
  12. parent: ActivatedRoute | null
  13. firstChild: ActivatedRoute | null
  14. children: ActivatedRoute[]
  15. pathFromRoot: ActivatedRoute[]
  16. paramMap: Observable<ParamMap>
  17. queryParamMap: Observable<ParamMap>
  18. toString(): string
  19. }

Description

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

Properties

Property Description
snapshot: ActivatedRouteSnapshot

The current snapshot of this route

url: Observable<UrlSegment[]>

An observable of the URL segments matched by this route

params: Observable<Params>

An observable of the matrix parameters scoped to this route

queryParams: Observable<Params>

An observable of the query parameters shared by all the routes

fragment: Observable<string>

An observable of the URL fragment shared by all the routes

data: Observable<Data>

An observable of the static and resolved data of this route.

outlet: string

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

component: Type<any> | string | null

The component of the route. It's a constant

routeConfig: Route | null Read-only.

The configuration used to match this route

root: ActivatedRoute Read-only.

The root of the router state

parent: ActivatedRoute | null Read-only.

The parent of this route in the router state tree

firstChild: ActivatedRoute | null Read-only.

The first child of this route in the router state tree

children: ActivatedRoute[] Read-only.

The children of this route in the router state tree

pathFromRoot: ActivatedRoute[] Read-only.

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

paramMap: Observable<ParamMap> Read-only.
queryParamMap: Observable<ParamMap> Read-only.

Methods

toString(): string
      
      toString(): string
    

Parameters

There are no parameters.

Returns

string