/** * @license * Copyright Stbui All Rights Reserved. * https://github.com/stbui/prophet */ import React, { Children, cloneElement, createElement, FunctionComponent, ComponentType, } from 'react'; import { Redirect, Route, Switch } from 'react-router-dom'; import { WithPermissions } from '../auth'; export interface CoreRoutesWithLayoutProps { catchAll?: any; children?: ComponentType; customRoutes?: any[]; dashboard?: ComponentType; title?: string; } const CoreRoutesWithLayout: FunctionComponent = ({ catchAll, children, customRoutes, dashboard, title, }) => { const childrenArray = Children.toArray(children); const firstChild: any = childrenArray.length > 0 ? childrenArray[0] : null; return ( {customRoutes && customRoutes.map((route, key) => cloneElement(route, { key }))} {Children.map(children, (child: any) => ( cloneElement(child, { intent: 'route', ...props }) } /> ))} {dashboard ? ( ( )} /> ) : firstChild ? ( } /> ) : null} createElement(catchAll, { ...routeProps, title, }) } /> ); }; export default CoreRoutesWithLayout;