填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

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);
    //...
  }
}
    

构造函数

      
      constructor(url: string, root: TreeNode<ActivatedRouteSnapshot>)
    
参数
url string

The url from which this snapshot was created

root TreeNode

属性

属性说明
url: string声明在构造函数中

The url from which this snapshot was created

方法

      
      toString(): string
    
参数

没有参数。

返回值

string