mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
21 lines
814 B
TypeScript
21 lines
814 B
TypeScript
import { ActivatedRouteSnapshot, Router } from '@angular/router';
|
|
import { hasValue } from '../empty.util';
|
|
import { URLCombiner } from '../../core/url-combiner/url-combiner';
|
|
|
|
/**
|
|
* Util function to retrieve the current path (without query parameters) the user is on
|
|
* @param router The router service
|
|
*/
|
|
export function currentPath(router: Router) {
|
|
const urlTree = router.parseUrl(router.url);
|
|
return '/' + urlTree.root.children.primary.segments.map((it) => it.path).join('/')
|
|
}
|
|
|
|
export function currentPathFromSnapshot(route: ActivatedRouteSnapshot): string {
|
|
if (hasValue(route.parent)) {
|
|
const parentRoute: string = currentPathFromSnapshot(route.parent);
|
|
return new URLCombiner(parentRoute, route.routeConfig.path).toString();
|
|
}
|
|
return route.routeConfig ? route.routeConfig.path : '';
|
|
}
|