/Angular 2 TypeScript


Stable Interface

What it does

Represents the parsed URL.

How to use

class MyComponent {
  constructor(router: Router) {
    const tree: UrlTree =
    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'

Interface Overview

interface UrlTree {
  root : UrlSegmentGroup
  queryParams : {[key: string]: string}
  fragment : string
  toString() : string

Interface Description

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

Interface Details

root : UrlSegmentGroup

The root segment group of the URL tree

queryParams : {[key: string]: string}

The query params of the URL

fragment : string

The fragment of the URL

toString() : string

exported from @angular/router/index, defined in @angular/router/src/url_tree.ts

© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.