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 Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^