UrlSegment Interface - UrlSegment
interface represents a single URL segment and the constructor, properties, and
methods look like below UrlSegment class i.e.
classUrlSegment {
constructor(path: string, parameters: {...})
path: string
parameters: {...}
toString(): string
}
The UrlSegment
is a part of a URL between the two slashes and it contains a path and matrix parameters
associated with the segment.
Stayed
In formed - Angular 7 Interview Questions
Example:
@Component({
templateUrl:'./user.component.html',
styleUrls: ['./user.component.css']
})
classUserComponent {
constructor(router: Router) {
consturlTree: UrlTree = router.parseUrl('/user;id=101');
consturlSGroup: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
consturlSegment: UrlSegment[] = urlSGroup.segments;
urlSegment[0].path; // It will returns 'user'
urlSegment[0].parameters; //It will returns {id: 101}
}
}