填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

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...

建構函式

      
      constructor(root: UrlSegmentGroup, queryParams: Params, fragment: string)
    
引數
root UrlSegmentGroup

The root segment group of the URL tree

queryParams Params

The query params of the URL

fragment string

The fragment of the URL

屬性

屬性說明
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
    
引數

沒有引數。

返回值

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