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

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

方法

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

没有参数。

返回值

string

使用说明

范例

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