Created
September 7, 2017 12:23
-
-
Save mh-rafi/c0b11bc43050d883cf30846e8c2cd4bf to your computer and use it in GitHub Desktop.
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
interface IRoutePart { | |
title: string, | |
breadcrumb: string, | |
params?: Params, | |
url: string, | |
urlSegments: any[] | |
} | |
@Injectable() | |
export class RoutePartsService { | |
public routeParts: IRoutePart[]; | |
constructor(private router: Router) {} | |
ngOnInit() { | |
} | |
generateRouteParts(snapshot: ActivatedRouteSnapshot): IRoutePart[] { | |
var routeParts = <IRoutePart[]>[]; | |
if (snapshot) { | |
if (snapshot.firstChild) { | |
routeParts = routeParts.concat(this.generateRouteParts(snapshot.firstChild)); | |
} | |
if (snapshot.url.length) { | |
routeParts.push({ | |
title: snapshot.data['title'], | |
breadcrumb: snapshot.data['breadcrumb'], | |
url: snapshot.url[0].path, | |
urlSegments: snapshot.url, | |
params: snapshot.params | |
}); | |
} | |
} | |
return routeParts; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment