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

RouterStatelink

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

Represents the state of the router as a tree of activated routes.

\n\n \n
\n \n \n
\n\ninterface RouterState extends Tree {\n snapshot: RouterStateSnapshot\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
\n

Propertieslink

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PropertyDescription
\n \n snapshot: RouterStateSnapshot\n \n \n

The current snapshot of the router state

\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

Usage noteslink

\n

Every node in the route tree is an ActivatedRoute instance\nthat knows about the \"consumed\" URL segments, the extracted parameters,\nand the resolved data.\nUse the ActivatedRoute properties to traverse the tree from any node.

\n

The following fragment shows how a component gets the root node\nof the current state to establish its own route tree:

\n\n@Component({templateUrl:'template.html'})\nclass MyComponent {\n constructor(router: Router) {\n const state: RouterState = router.routerState;\n const root: ActivatedRoute = state.root;\n const child = root.firstChild;\n const id: Observable<string> = child.params.map(p => p.id);\n //...\n }\n}\n\n\n
\n\n\n\n
\n
\n\n\n" }