W3cubDocs

/Angular

UrlSegment

class final

Represents a single URL segment.

See more...

class UrlSegment {
  constructor(path: string, parameters: { [name: string]: string; })
  path: string
  parameters: {...}
  parameterMap: ParamMap
  toString(): string
}

Description

A UrlSegment is a part of a URL between the two slashes. It contains a path and the matrix parameters associated with the segment.

Further information is available in the Usage Notes...

Constructor

constructor(path: string, parameters: { [name: string]: string; })

Parameters
path string

The path part of a URL segment

parameters object

The matrix parameters associated with a segment

Properties

Property Description
path: string Declared in Constructor

The path part of a URL segment

parameters: { [name: string]: string; } Declared in Constructor

The matrix parameters associated with a segment

parameterMap: ParamMap Read-Only

Methods

toString(): string

Parameters

There are no parameters.

Returns

string

Usage notes

Example

@Component({templateUrl:'template.html'})
class MyComponent {
  constructor(router: Router) {
    const tree: UrlTree = router.parseUrl('/team;id=33');
    const g: UrlSegmentGroup = tree.root.children[PRIMARY_OUTLET];
    const s: UrlSegment[] = g.segments;
    s[0].path; // returns 'team'
    s[0].parameters; // returns {id: 33}
  }
}

© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/router/UrlSegment