UrlTree
代表已解析的 URL。
Represents the parsed URL.
class UrlTree {
root: UrlSegmentGroup
queryParams: Params
fragment: string | null
queryParamMap: ParamMap
toString(): string
}
说明
由于路由器状态是一棵树,而 URL 只是序列化的状态,所以 URL 就是序列化的树。 UrlTree 是一种数据结构,在处理 URL 时提供了很多便利
Since a router state is a tree, and the URL is nothing but a serialized state, the URL is a serialized tree. UrlTree is a data structure that provides a lot of affordances in dealing with URLs
Further information available in the Usage Notes...
构造函数
参数
|
属性
属性 | 说明 |
---|---|
root: UrlSegmentGroup | 声明在构造函数中 The root segment group of the URL tree |
queryParams: Params | 声明在构造函数中 The query params of the URL |
fragment: string | null | 声明在构造函数中 The fragment of the URL |
queryParamMap: ParamMap | 只读 |
方法
参数没有参数。 返回值
|
使用说明
例子
Example
@Component({templateUrl:'template.html'})
class MyComponent {
constructor(router: Router) {
const tree: UrlTree =
router.parseUrl('/team/33/(user/victor//support:help)?debug=true#fragment');
const f = tree.fragment; // return 'fragment'
const q = tree.queryParams; // returns {debug: 'true'}
const g: UrlSegmentGroup = tree.root.children[PRIMARY_OUTLET];
const s: UrlSegment[] = g.segments; // returns 2 segments 'team' and '33'
g.children[PRIMARY_OUTLET].segments; // returns 2 segments 'user' and 'victor'
g.children['support'].segments; // return 1 segment 'help'
}
}