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

UrlTree

Represents the parsed URL.

查看"说明"...

      
      interface UrlTree {
  root: UrlSegmentGroup
  queryParams: Params
  fragment: string | null
  queryParamMap: ParamMap
  toString(): string
}
    

说明

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

属性

属性说明
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只读

方法

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

没有参数。

返回值

string

使用说明

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' } }
      
      @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'
  }
}