多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## UrlTree 表示解析过后的URL ### 如何使用 ```typescript @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']; const s: UrlSegment[] = g.segments; // returns 2 segments 'team' and '33' g.children['primary'].segments; // returns 2 segments 'user' and 'victor' g.children['support'].segments; // return 1 segment 'help' } } ``` ### 接口定义 ```typescript interface UrlTree { root : UrlSegmentGroup queryParams : {[key: string]: string} fragment : string toString() : string } ``` ### 接口描述 既然路由器状态可以描述成一棵树,那么URL也不过是一棵序列化过后的状态树。UrlTree 本身的数据结构就提供了对于URLs操作的大量启示。 ### 属性 - root : `UrlSegmentGroup` URL树的节点所包含的片段分组 - queryParams : {[key: `string`]: `string`} URL的查询参数 - fragment : `string` URL的片段 - toString() : `string`