Skip to content

Instantly share code, notes, and snippets.

@Purecaesar
Created July 5, 2021 10:06
Show Gist options
  • Save Purecaesar/880908c5475c9354c208ef1269195d7a to your computer and use it in GitHub Desktop.
Save Purecaesar/880908c5475c9354c208ef1269195d7a to your computer and use it in GitHub Desktop.
import { ActivatedRoute } from "@angular/router";
export function getRouteWithData(route: ActivatedRoute, fieldName: string, propagation: boolean): ActivatedRoute {
do {
if (fieldName in route.snapshot.data) return route;
route = route.parent;
} while (route && propagation);
if (propagation) throw new Error(`Field ${fieldName} didn't find in route tree`);
throw new Error (`Field ${fieldName} didn't find in current route`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment