Created
May 24, 2023 12:15
-
-
Save maximLyakhov/f2b703ce897bc04702dce87d8845b1ec to your computer and use it in GitHub Desktop.
Angular Router: function to map module path recursively
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
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