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

RouterStateSnapshotlink

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

Represents the state of the router at a moment in time.

\n\n

See more...

\n
\n \n \n
\n\ninterface RouterStateSnapshot extends Tree {\n url: string\n toString(): string\n}\n\n\n \n \n\n\n \n \n\n
\n\n \n\n \n \n
\n

Descriptionlink

\n

This is a tree of activated route snapshots. Every node in this tree knows about\nthe \"consumed\" URL segments, the extracted parameters, and the resolved data.

\n

The following example shows how a component is initialized with information\nfrom the snapshot of the root node's state at the time of creation.

\n\n@Component({templateUrl:'template.html'})\nclass MyComponent {\n constructor(router: Router) {\n const state: RouterState = router.routerState;\n const snapshot: RouterStateSnapshot = state.snapshot;\n const root: ActivatedRouteSnapshot = snapshot.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

Propertieslink

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PropertyDescription
\n \n url: string\n \n \n

The url from which this snapshot was created

\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" }