import * as React from "react"; import { RouteConfig, matchRoutes, MatchedRoute, renderRoutes, RouteConfigComponentProps } from "react-router-config"; import { BrowserRouter } from "react-router-dom"; const Root = ({ route }: RouteConfigComponentProps) => (

Root

{/* child routes won't render without this */} {renderRoutes(route && route.routes)}
); const Home = ({ route }: RouteConfigComponentProps) => (

Home

); const Child = ({ route }: RouteConfigComponentProps<{ id: string }>) => (

Child

{/* child routes won't render without this */} {route && renderRoutes(route.routes, null, {})}
); const GrandChild = () => (

Grand Child

); // route config const routes: RouteConfig[] = [ { component: Root, routes: [ { path: "/", exact: true, component: Home }, { path: "/child/:id", component: Child, routes: [{ path: "/child/:id/grand-child", component: GrandChild }], loadData: () => Promise.resolve({}) } ] } ]; const branch: Array> = matchRoutes<{}>(routes, "/child/23"); // using the routes shown earlier, this returns // [ // routes[0], // routes[0].routes[1] // ] // pass this into ReactDOM.render {renderRoutes(routes)};