{ "id": "api/router/ActivatedRoute", "title": "ActivatedRoute", "contents": "\n\n
\n
\n
\n \n API > @angular/router\n
\n \n
\n \n
\n

ActivatedRoutelink

\n \n \n \n \n \n
\n \n \n\n
\n \n
\n

Provides access to information about a route associated with a component\nthat is loaded in an outlet.\nUse to traverse the RouterState tree and extract information from nodes.

\n\n

See more...

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

See alsolink

\n \n
\n\n\n \n \n
\n

Descriptionlink

\n

The following example shows how to construct a component using information from a\ncurrently activated route.

\n\nimport {Component} from '@angular/core';\n/* . . . */\nimport {ActivatedRoute} from '@angular/router';\nimport {Observable} from 'rxjs';\nimport {map} from 'rxjs/operators';\n/* . . . */\n\n@Component({\n/* . . . */\n})\nexport class ActivatedRouteComponent {\n constructor(route: ActivatedRoute) {\n const id: Observable<string> = route.params.pipe(map(p => p.id));\n const url: Observable<string> = route.url.pipe(map(segments => segments.join('')));\n // route.data includes both `data` and `resolve`\n const user = route.data.pipe(map(d => d.user));\n }\n}\n\n\n\n \n
\n\n \n
\n

Propertieslink

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PropertyDescription
\n \n snapshot: ActivatedRouteSnapshot\n \n \n

The current snapshot of this route

\n\n \n
\n \n url: Observable<UrlSegment[]>\n \n \n

An observable of the URL segments matched by this route.

\n\n \n
\n \n params: Observable<Params>\n \n \n

An observable of the matrix parameters scoped to this route.

\n\n \n
\n \n queryParams: Observable<Params>\n \n \n

An observable of the query parameters shared by all the routes.

\n\n \n
\n \n fragment: Observable<string | null>\n \n \n

An observable of the URL fragment shared by all the routes.

\n\n \n
\n \n data: Observable<Data>\n \n \n

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

\n\n \n
\n \n outlet: string\n \n \n

The outlet name of the route, a constant.

\n\n \n
\n \n component: Type<any> | string | null\n \n \n

The component of the route, a constant.

\n\n \n
\n \n routeConfig: Route | null\n Read-Only\n \n

The configuration used to match this route.

\n\n \n
\n \n root: ActivatedRoute\n Read-Only\n \n

The root of the router state.

\n\n \n
\n \n parent: ActivatedRoute | null\n Read-Only\n \n

The parent of this route in the router state tree.

\n\n \n
\n \n firstChild: ActivatedRoute | null\n Read-Only\n \n

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

\n\n \n
\n \n children: ActivatedRoute[]\n Read-Only\n \n

The children of this route in the router state tree.

\n\n \n
\n \n pathFromRoot: ActivatedRoute[]\n Read-Only\n \n

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

\n\n \n
\n \n paramMap: Observable<ParamMap>\n Read-Only\n \n

An Observable that contains a map of the required and optional parameters\nspecific to the route.\nThe map supports retrieving single and multiple values from the same parameter.

\n\n \n
\n \n queryParamMap: Observable<ParamMap>\n Read-Only\n \n

An Observable that contains a map of the query parameters available to all routes.\nThe map supports retrieving single and multiple values from the query parameter.

\n\n \n
\n
\n \n\n
\n

Methodslink

\n \n \n\n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n toString()\n \n link

\n \n
\n
\n
\n \n\n toString(): string\n\n \n\n
Parameters
\n

There are no parameters.

\n\n \n
Returns
\n

string

\n\n \n\n\n \n\n \n
\n
\n\n \n
\n\n\n \n\n\n
\n
\n\n\n" }