import React, { useMemo, useState } from 'react' import { Route, Redirect, Switch } from 'react-router-dom' import { Layout } from 'antd' import routes, { RouteItem } from '@/config/routes' import { defaultSettings, logo } from '@/config' import { useAuth } from '@/hooks' import CustomHeader from './header' import CustomFooter from './footer' import SideBar from './menu' import HomePage from '@/pages/index' const { Content } = Layout const PrivateRoute: React.FC = (props) => { const { children, component, path, auth: needAuth = false, location, ...rest } = props const auth = useAuth() return ( <> {!auth.user && needAuth ? ( ) : ( )} ) } const cleanRoutes = (routes: RouteItem[], needAuth = false): RouteItem[] => { return routes .map((route) => { if (route.hideInRoute) { return null } const finalRoute = { auth: needAuth, ...route } const auth = finalRoute.auth if (route.children) { return cleanRoutes(route.children, auth) } return finalRoute }) .filter(Boolean) .flat(1) as RouteItem[] } const BaseLayout: React.FC = () => { const [collapsed, setCollapsed] = useState(false) const [theme] = useState<'light' | 'dark'>(defaultSettings.theme) const siderWidth = 208 const cleanRoute = useMemo(() => cleanRoutes(routes), [routes]) return ( {cleanRoute.map((route, index) => ( ))} ) } export default BaseLayout