RouterStateSnapshot

Represents the state of the router at a moment in time.

表示路由器在当前瞬间的状态。

interface RouterStateSnapshot extends Tree{ url: string toString(): string }

说明

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 片段、已提取出的参数和已解析出的数据。

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

属性

属性名类型说明
url

The url from which this snapshot was created

方法

toString(): string

参数

没有参数。

返回值

string