How do you get the first part of a URI in Angular 5?

Solution 1:

Ok I found the answer from Angular's doc, you have to use the UrlSegment Angular class from @angular/router to parse the url in segments link to the relevant doc: https://angular.io/api/router/UrlSegment

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}