RouterStateSnapshot
表示路由器在当前瞬间的状态。
Represents the state of the router at a moment in time.
class 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.
以下示例演示了如何使用创建时根节点状态快照中的信息初始化组件。
The following example shows how a component is initialized with information from the snapshot of the root node's state at the time of creation.
@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);
//...
}
}
构造函数
参数
|
属性
属性 | 说明 |
---|---|
url: string | 声明在构造函数中 The url from which this snapshot was created |
方法
参数没有参数。 返回值
|