import React from 'react';
import { Redirect, Route, Switch } from 'react-router-dom';
import { RouteContext } from './context';
import { useRouteComponent } from './hooks';
import { RouteSwitchProps } from './types';
export function RouteSwitch(props: RouteSwitchProps) {
const { routes = [] } = props;
if (!routes.length) {
return null;
}
return (
{routes.map((route, index) => {
if (route.type == 'redirect') {
return (
);
}
if (!route.path && Array.isArray(route.routes)) {
route.path = route.routes.map((r) => r.path) as any;
}
return (
{
return (
);
}}
/>
);
})}
);
}
function ComponentRenderer(props) {
const Component = useRouteComponent(props?.route?.component);
return (
);
}