Angular 7 UrlSegment Interface

What Is UrlSegment Interface in Angular 7?

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


ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

What Is UrlSegment Interface in Angular 7? What Is UrlSegment Interface in Angular 7? Reviewed by Anil Singh on 9:24 PM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^