Skip to content

Instantly share code, notes, and snippets.

@dovidweisz
Created June 10, 2020 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dovidweisz/ab78e70d6ad4d951a856e292b995865d to your computer and use it in GitHub Desktop.
Save dovidweisz/ab78e70d6ad4d951a856e292b995865d to your computer and use it in GitHub Desktop.
Flatten React Router routes into one array
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