linkActivatedRoute
npm Package | @angular/router |
---|---|
Module | import { ActivatedRoute } from '@angular/router'; |
Source | router/src/router_state.ts |
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.
linkInterface 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 | null
get routeConfig: Route | null
get root: ActivatedRoute
get parent: ActivatedRoute | null
get firstChild: ActivatedRoute | null
get children: ActivatedRoute[]
get pathFromRoot: ActivatedRoute[]
get paramMap: Observable<ParamMap>
get queryParamMap: Observable<ParamMap>
toString(): string
}
linkHow To Use
@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);
}
}
linkMembers
get paramMap: Observable<ParamMap>
get queryParamMap: Observable<ParamMap>