Skip to content

Commit

Permalink
feat(#13): add option to add a frame around routes with RouterRoutes
Browse files Browse the repository at this point in the history
  • Loading branch information
DevNico committed Nov 9, 2021
1 parent 172c5cf commit adc2e46
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/components/RouterRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { anyRouterToRouteList } from '../utils/routerUtils';
*/
interface RouterRoutesProps {
router: AnyRouterType;
frame: React.ReactElement<React.PropsWithChildren<any>>;
}

/**
Expand All @@ -16,19 +17,25 @@ interface RouterRoutesProps {
* @param props - Props containing the router to use
*/
export const RouterRoutes = (props: RouterRoutesProps) => {
return (
<Routes>
{anyRouterToRouteList(props.router).map((route, index) => {
const Element = route.render();
return (
<Route
key={index}
path={route.fullTemplate}
caseSensitive={route.caseSensitive}
element={Element}
/>
);
})}
</Routes>
);
const routes = anyRouterToRouteList(props.router).map((route, index) => {
const Element = route.render();
return (
<Route
key={index}
path={route.fullTemplate}
caseSensitive={route.caseSensitive}
element={Element}
/>
);
});

if (props.frame) {
const frame = React.cloneElement(props.frame, {
children: <>{routes}</>,
});

return <Routes>{frame}</Routes>;
}

return <Routes>{routes}</Routes>;
};

0 comments on commit adc2e46

Please sign in to comment.