mirror of https://gitlab.com/ecentrics/concordia
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.6 KiB
60 lines
1.6 KiB
4 years ago
|
import React, { Fragment, lazy, Suspense } from 'react';
|
||
|
import { Redirect, Route, Switch } from 'react-router-dom';
|
||
|
import CoreLayoutContainer from './layout/CoreLayoutContainer';
|
||
|
import LoadingScreen from './components/LoadingScreen';
|
||
|
|
||
|
const routesConfig = [
|
||
|
{
|
||
|
exact: true,
|
||
|
path: '/404',
|
||
|
component: lazy(() => import('./components/NotFound')),
|
||
|
},
|
||
|
{
|
||
|
path: '*',
|
||
|
layout: CoreLayoutContainer,
|
||
|
routes: [
|
||
|
{
|
||
|
exact: true,
|
||
|
path: '/',
|
||
|
component: lazy(() => import('./components/HomeContainer')),
|
||
|
},
|
||
|
{
|
||
|
component: () => <Redirect to="/404" />,
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
];
|
||
|
|
||
|
const renderRoutes = (routes) => (routes ? (
|
||
|
<Suspense fallback={<LoadingScreen />}>
|
||
|
<Switch>
|
||
|
{routes.map((route, i) => {
|
||
|
const Layout = route.layout || Fragment;
|
||
|
const Component = route.component;
|
||
|
|
||
|
const key = route.path ? route.path.concat(i) : ''.concat(i);
|
||
|
return (
|
||
|
<Route
|
||
|
key={key}
|
||
|
path={route.path}
|
||
|
exact={route.exact}
|
||
|
render={(props) => (
|
||
|
<Layout>
|
||
|
{route.routes
|
||
|
? renderRoutes(route.routes)
|
||
|
: <Component {...props} />}
|
||
|
</Layout>
|
||
|
)}
|
||
|
/>
|
||
|
);
|
||
|
})}
|
||
|
</Switch>
|
||
|
</Suspense>
|
||
|
) : null);
|
||
|
|
||
|
function Routes() {
|
||
|
return renderRoutes(routesConfig);
|
||
|
}
|
||
|
|
||
|
export default Routes;
|