Represents the state of the router as a tree of activated routes.
API
class RouterState extends Tree<ActivatedRoute> {
constructor(root: TreeNode<ActivatedRoute>, snapshot: RouterStateSnapshot): RouterState;
override snapshot: RouterStateSnapshot;
toString(): string;
override readonly root: T;
}
constructor
RouterState
@returns
RouterState
snapshot
RouterStateSnapshotThe current snapshot of the router state
toString
string
@returns
string
root
TUsage Notes
Every node in the route tree is an ActivatedRoute instance that knows about the "consumed" URL segments, the extracted parameters, and the resolved data. Use the ActivatedRoute properties to traverse the tree from any node.
The following fragment shows how a component gets the root node of the current state to establish its own route tree:
@Component({templateUrl:'template.html'})
class MyComponent {
constructor(router: Router) {
const state: RouterState = router.routerState;
const root: ActivatedRoute = state.root;
const child = root.firstChild;
const id: Observable<string> = child.params.map(p => p.id);
//...
}
}