|
|
@ -6,40 +6,41 @@ import { pageList } from "@/plugins/pageHoc" |
|
|
|
import Layout from "@/views/Layout" |
|
|
|
|
|
|
|
import Auth from "@/ui/Auth" |
|
|
|
import routes,{Loading} from "./route" |
|
|
|
import routes from "./route" |
|
|
|
|
|
|
|
function Wrapper(props: any) { |
|
|
|
if (!props.isSub) { |
|
|
|
return <React.Suspense fallback={<Loading></Loading>}>{props.children}</React.Suspense> |
|
|
|
if (props.loading) { |
|
|
|
return <React.Suspense fallback={<props.loading></props.loading>}>{props.children}</React.Suspense> |
|
|
|
} |
|
|
|
return <Fragment>{props.children}</Fragment> |
|
|
|
} |
|
|
|
|
|
|
|
function RouteMap(props: any) { |
|
|
|
const routes: any[] = props.routes |
|
|
|
const isSub: boolean = props.isSub |
|
|
|
return ( |
|
|
|
<Wrapper isSub={isSub}> |
|
|
|
<Switch> |
|
|
|
{routes.map((route, index) => { |
|
|
|
const { exact = false } = route |
|
|
|
if (route.redirect) { |
|
|
|
return ( |
|
|
|
<Route key={index} path={route.path} exact={exact}> |
|
|
|
<Redirect to={route.redirect}></Redirect> |
|
|
|
</Route> |
|
|
|
) |
|
|
|
} |
|
|
|
if (route.component) { |
|
|
|
return ( |
|
|
|
<Auth key={index} needAuth={!!route.meta?.auth} path={route.path} exact={exact}> |
|
|
|
<route.component meta={route.meta}>{route.children && <RouteMap routes={route.children} isSub></RouteMap>}</route.component> |
|
|
|
</Auth> |
|
|
|
) |
|
|
|
} |
|
|
|
})} |
|
|
|
</Switch> |
|
|
|
</Wrapper> |
|
|
|
<Switch> |
|
|
|
{routes.map((route, index) => { |
|
|
|
const { exact = false } = route |
|
|
|
if (route.redirect) { |
|
|
|
return ( |
|
|
|
<Route key={index} path={route.path} exact={exact}> |
|
|
|
<Redirect to={route.redirect}></Redirect> |
|
|
|
</Route> |
|
|
|
) |
|
|
|
} |
|
|
|
if (route.component) { |
|
|
|
return ( |
|
|
|
<Auth key={index} needAuth={!!route.meta?.auth} path={route.path} exact={exact}> |
|
|
|
<Wrapper loading={route.loading}> |
|
|
|
<route.component meta={route.meta}> |
|
|
|
{route.children && <RouteMap routes={route.children}></RouteMap>} |
|
|
|
</route.component> |
|
|
|
</Wrapper> |
|
|
|
</Auth> |
|
|
|
) |
|
|
|
} |
|
|
|
})} |
|
|
|
</Switch> |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
@ -48,11 +49,12 @@ export default function () { |
|
|
|
|
|
|
|
return ( |
|
|
|
<Router> |
|
|
|
<Layout |
|
|
|
<RouteMap routes={routes}></RouteMap> |
|
|
|
{/* <Layout |
|
|
|
render={() => { |
|
|
|
return <RouteMap routes={routes}></RouteMap> |
|
|
|
}} |
|
|
|
></Layout> |
|
|
|
></Layout> */} |
|
|
|
</Router> |
|
|
|
) |
|
|
|
} |
|
|
|