mirror of https://gitlab.com/ecentrics/concordia
Apostolos Fanakis
4 years ago
7 changed files with 103 additions and 44 deletions
@ -0,0 +1,25 @@ |
|||||
|
import React from 'react'; |
||||
|
import { Provider } from 'react-redux'; |
||||
|
import { BrowserRouter as Router } from 'react-router-dom'; |
||||
|
import PropTypes from 'prop-types'; |
||||
|
import LoadingContainer from './components/LoadingContainer'; |
||||
|
import Routes from './Routes'; |
||||
|
|
||||
|
// CSS |
||||
|
import './assets/css/app.css'; |
||||
|
|
||||
|
const App = ({ store }) => ( |
||||
|
<Provider store={store}> |
||||
|
<LoadingContainer> |
||||
|
<Router> |
||||
|
<Routes /> |
||||
|
</Router> |
||||
|
</LoadingContainer> |
||||
|
</Provider> |
||||
|
); |
||||
|
|
||||
|
App.propTypes = { |
||||
|
store: PropTypes.object.isRequired, |
||||
|
}; |
||||
|
|
||||
|
export default App; |
@ -0,0 +1,59 @@ |
|||||
|
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; |
@ -1,33 +0,0 @@ |
|||||
import React from 'react'; |
|
||||
import { Provider } from 'react-redux'; |
|
||||
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; |
|
||||
import PropTypes from 'prop-types'; |
|
||||
import LoadingContainer from './LoadingContainer'; |
|
||||
|
|
||||
// CSS |
|
||||
import '../assets/css/app.css'; |
|
||||
|
|
||||
import CoreLayoutContainer from './CoreLayoutContainer'; |
|
||||
import HomeContainer from './HomeContainer'; |
|
||||
import NotFound from './NotFound'; |
|
||||
|
|
||||
const App = ({ store }) => ( |
|
||||
<Provider store={store}> |
|
||||
<LoadingContainer> |
|
||||
<Router> |
|
||||
<CoreLayoutContainer> |
|
||||
<Switch> |
|
||||
<Route exact path="/" component={HomeContainer} /> |
|
||||
<Route component={NotFound} /> |
|
||||
</Switch> |
|
||||
</CoreLayoutContainer> |
|
||||
</Router> |
|
||||
</LoadingContainer> |
|
||||
</Provider> |
|
||||
); |
|
||||
|
|
||||
App.propTypes = { |
|
||||
store: PropTypes.object.isRequired, |
|
||||
}; |
|
||||
|
|
||||
export default App; |
|
@ -0,0 +1,9 @@ |
|||||
|
import React from 'react'; |
||||
|
|
||||
|
const LoadingScreen = () => ( |
||||
|
<div> |
||||
|
Loading |
||||
|
</div> |
||||
|
); |
||||
|
|
||||
|
export default LoadingScreen; |
@ -1,7 +1,7 @@ |
|||||
import React from 'react'; |
import React from 'react'; |
||||
import PropTypes from 'prop-types'; |
import PropTypes from 'prop-types'; |
||||
|
|
||||
import MenuComponent from './MenuComponent'; |
import MenuComponent from '../components/MenuComponent'; |
||||
|
|
||||
const CoreLayout = (props) => { |
const CoreLayout = (props) => { |
||||
const { children } = props; |
const { children } = props; |
Loading…
Reference in new issue