Skip to content

Instantly share code, notes, and snippets.

@maximLyakhov
Created May 24, 2023 12:15
Show Gist options
  • Save maximLyakhov/f2b703ce897bc04702dce87d8845b1ec to your computer and use it in GitHub Desktop.
Save maximLyakhov/f2b703ce897bc04702dce87d8845b1ec to your computer and use it in GitHub Desktop.
Angular Router: function to map module path recursively
export function createViewRoute(
originalRoute: Route,
parentPath: string
): unknown {
const guardString = defaultTo('');
const guardArr = defaultTo([]);
type ViewRoute = Route & {_loadedRoutes: Routes} & {fullPath: string};
const castRoute = originalRoute as ViewRoute;
const fullPath =
parentPath +
(originalRoute.path ? '/' + originalRoute.path : originalRoute.path);
castRoute.fullPath = fullPath;
const children = guardArr(prop('children', castRoute));
const loadedRoutes = guardArr(prop('_loadedRoutes', castRoute));
const allChildren: Route[] = concat(children, loadedRoutes);
return {
children: allChildren.map((r) => createViewRoute(r, fullPath)),
path: castRoute.path,
title: guardString(castRoute.title),
fullPath,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment