Created
June 10, 2020 14:02
-
-
Save dovidweisz/ab78e70d6ad4d951a856e292b995865d to your computer and use it in GitHub Desktop.
Flatten React Router routes into one array
This file contains hidden or 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
import { RouteConfig } from "react-router-config"; | |
function flattenRoutes(routes: RouteConfig[]): RouteConfig[] { | |
return [ | |
...routes, | |
...routes.reduce<RouteConfig[]>( | |
(accum, route) => [...accum, ...(route.routes ? flattenRoutes(route.routes) : [])], | |
[] | |
), | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment