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

RouterState

将路由器的状态表示为已激活路由的树。

Represents the state of the router as a tree of activated routes.

      
      class RouterState extends Tree {
  snapshot: RouterStateSnapshot
  toString(): string
}
    

参见

构造函数

      
      constructor(root: TreeNode<ActivatedRoute>, snapshot: RouterStateSnapshot)
    
参数
root TreeNode
snapshot RouterStateSnapshot

The current snapshot of the router state

属性

属性说明
snapshot: RouterStateSnapshot声明在构造函数中

The current snapshot of the router state

方法

      
      toString(): string
    
参数

没有参数。

返回值

string

使用说明

路由树中的每个节点都是 ActivatedRoute 的实例,该实例了解“已消耗的” URL 段,已提取的参数和已解析的数据。使用 ActivatedRoute 属性可以从任何节点遍历树。

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