ActivatedRouteSnapshot
Contains the information about a route associated with a component loaded in an outlet at a particular moment in time. ActivatedRouteSnapshot can also be used to traverse the router state tree.
constructor
ActivatedRouteSnapshotParamsThe matrix parameters scoped to this route.
You can compute all params (or data) in the router state or to get params outside
of an activated component by traversing the RouterState tree as in the following
example:
collectRouteParams(router: Router) { let params = {}; let stack: ActivatedRouteSnapshot[] = [router.routerState.snapshot.root]; while (stack.length > 0) { const route = stack.pop()!; params = {...params, ...route.params}; stack.push(...route.children); } return params;}
string | nullThe URL fragment shared by all the routes
stringThe outlet name of the route
ActivatedRouteSnapshotrouteConfig
Route | nullThe configuration used to match this route *
title
string | undefinedThe resolved route title
url
UrlSegment[]The URL segments matched by this route
params
ParamsThe matrix parameters scoped to this route.
You can compute all params (or data) in the router state or to get params outside
of an activated component by traversing the RouterState tree as in the following
example:
collectRouteParams(router: Router) { let params = {}; let stack: ActivatedRouteSnapshot[] = [router.routerState.snapshot.root]; while (stack.length > 0) { const route = stack.pop()!; params = {...params, ...route.params}; stack.push(...route.children); } return params;}
queryParams
ParamsThe query parameters shared by all the routes
fragment
string | nullThe URL fragment shared by all the routes
data
DataThe static and resolved data of this route
outlet
stringThe outlet name of the route
component
Type<any> | nullThe component of the route
root
ActivatedRouteSnapshotThe root of the router state
parent
ActivatedRouteSnapshot | nullThe parent of this route in the router state tree
firstChild
ActivatedRouteSnapshot | nullThe first child of this route in the router state tree
children
ActivatedRouteSnapshot[]The children of this route in the router state tree
pathFromRoot
ActivatedRouteSnapshot[]The path from the root of the router state tree to this route
paramMap
ParamMapqueryParamMap
ParamMaptoString
stringstringDescription
Contains the information about a route associated with a component loaded in an outlet at a particular moment in time. ActivatedRouteSnapshot can also be used to traverse the router state tree.
The following example initializes a component with route information extracted from the snapshot of the root node at the time of creation.
@Component({templateUrl:'./my-component.html'})class MyComponent { constructor(route: ActivatedRoute) { const id: string = route.snapshot.params.id; const url: string = route.snapshot.url.join(''); const user = route.snapshot.data.user; }}