RouterStateSnapshot
表示路由器在当前瞬间的状态。
Represents the state of the router at a moment in time.
interface RouterStateSnapshot extends Tree {
url: string
toString(): string
}
说明
这是一个由活动路由的快照组成的树。本树中的每个节点都会知道 "已消费的" URL 片段、已提取出的参数和已解析出的数据。
This is a tree of activated route snapshots. Every node in this tree knows about the "consumed" URL segments, the extracted parameters, and the resolved data.
属性
属性 | 说明 |
---|---|
url: string | The url from which this snapshot was created |
方法
参数没有参数。 返回值
|
使用说明
范例
Example
@Component({templateUrl:'template.html'})
class MyComponent {
constructor(router: Router) {
const state: RouterState = router.routerState;
const snapshot: RouterStateSnapshot = state.snapshot;
const root: ActivatedRouteSnapshot = snapshot.root;
const child = root.firstChild;
const id: Observable<string> = child.params.map(p => p.id);
//...
}
}