填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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