{ "id": "api/router/UrlTree", "title": "UrlTree", "contents": "\n\n
\n
\n
\n \n API > @angular/router\n
\n \n
\n \n
\n

UrlTreelink

\n \n \n \n \n \n
\n \n \n\n
\n \n
\n

Represents the parsed URL.

\n\n

See more...

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

Descriptionlink

\n

Since a router state is a tree, and the URL is nothing but a serialized state, the URL is a\nserialized tree.\nUrlTree is a data structure that provides a lot of affordances in dealing with URLs

\n\n

Further information available in the Usage Notes...

\n
\n\n \n
\n

Propertieslink

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PropertyDescription
\n \n root: UrlSegmentGroup\n \n \n

The root segment group of the URL tree

\n\n \n
\n \n queryParams: Params\n \n \n

The query params of the URL

\n\n \n
\n \n fragment: string | null\n \n \n

The fragment of the URL

\n\n \n
\n \n queryParamMap: ParamMap\n Read-Only\n \n \n \n
\n
\n \n\n
\n

Methodslink

\n \n \n\n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n toString()\n \n link

\n \n
\n
\n
\n \n\n toString(): string\n\n \n\n
Parameters
\n

There are no parameters.

\n\n \n
Returns
\n

string

\n\n \n\n\n \n\n \n
\n
\n\n \n
\n\n\n \n
\n

Usage noteslink

\n

Examplelink

\n\n@Component({templateUrl:'template.html'})\nclass MyComponent {\n constructor(router: Router) {\n const tree: UrlTree =\n router.parseUrl('/team/33/(user/victor//support:help)?debug=true#fragment');\n const f = tree.fragment; // return 'fragment'\n const q = tree.queryParams; // returns {debug: 'true'}\n const g: UrlSegmentGroup = tree.root.children[PRIMARY_OUTLET];\n const s: UrlSegment[] = g.segments; // returns 2 segments 'team' and '33'\n g.children[PRIMARY_OUTLET].segments; // returns 2 segments 'user' and 'victor'\n g.children['support'].segments; // return 1 segment 'help'\n }\n}\n\n\n
\n\n\n\n
\n
\n\n\n" }