Created
December 12, 2017 02:59
-
-
Save gildniy/761f98bc7e13ec48c4de0f33a4ee312e to your computer and use it in GitHub Desktop.
Route segment Angular 4 service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { PRIMARY_OUTLET, Router, UrlSegment, UrlSegmentGroup, UrlTree } from '@angular/router'; | |
@Injectable() | |
export class RouteSegment { | |
constructor(private router: Router) { | |
} | |
path(position: number): string { | |
// REF: https://angular.io/api/router/UrlSegment | |
const tree: UrlTree = this.router.parseUrl(this.router.url); | |
const g: UrlSegmentGroup = tree.root.children[PRIMARY_OUTLET]; | |
const s: UrlSegment[] = g.segments; | |
return s[position].path; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment