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

RouterState

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

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

参见

属性

属性说明
snapshot: RouterStateSnapshot

The current snapshot of the router state

方法

toString(): string
      
      toString(): string
    
参数

没有参数。

返回值

string

使用说明

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.

Example

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