linkRouterState
npm Package | @angular/router |
---|---|
Module | import { RouterState } from '@angular/router'; |
Source | router/src/router_state.ts |
Represents the state of the router.
linkInterface Overview
interface RouterState extends Tree {
snapshot: RouterStateSnapshot
toString(): string
}
linkHow To Use
@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);
//...
}
}
linkDescription
RouterState is a tree of activated routes. Every node in this tree knows about the "consumed" URL segments, the extracted parameters, and the resolved data.
See ActivatedRoute
for more information.