Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

Commit

Permalink
feat(#115): enabled lazy loading for AppRoutes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Gasser committed May 20, 2019
1 parent a2ed29b commit da9e6f8
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions src/app/AppRoutes.jsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
import React from 'react';
import React, { Suspense } from 'react';
import PropTypes from 'prop-types';
import { Route, Switch } from 'react-router-dom';

import PrivateRoute from './PrivateRoute';
import AppLoadingView from './AppLoadingView';

import ImagesContainer from '../images/list/Container';
import ImagesDetailContainer from '../images/detail/Container';
import UserContainer from '../user/Container';
import * as Paths from '../paths';

import LoginContainer from '../auth/login/Container';
import RegisterContainer from '../auth/register/Container';
const ImagesContainer = React.lazy(() => import('../images/list/Container'));
const ImagesDetailContainer = React.lazy(() => import('../images/detail/Container'));
const UserContainer = React.lazy(() => import('../user/Container'));

import Privacy from './Privacy';
import NotFound from './NotFound';
const LoginContainer = React.lazy(() => import('../auth/login/Container'));
const RegisterContainer = React.lazy(() => import('../auth/register/Container'));

import * as Paths from '../paths';
const Privacy = React.lazy(() => import('./Privacy'));
const NotFound = React.lazy(() => import('./NotFound'));

// import * as Paths from '../paths';

const AppRoutes = ({ isAuthenticated }, ...props) => (
<Switch {...props}>
<PrivateRoute exact path={Paths.HOME} component={ImagesContainer} isAuthenticated={isAuthenticated} />
<PrivateRoute exact path={Paths.IMAGES} component={ImagesContainer} isAuthenticated={isAuthenticated} />
<PrivateRoute
exact
path={Paths.GET_IMAGES_DETAIL(Paths.ID)}
component={ImagesDetailContainer}
isAuthenticated={isAuthenticated}
/>
<PrivateRoute exact path={Paths.USER} component={UserContainer} isAuthenticated={isAuthenticated} />
<Route exact path={Paths.LOGIN} component={LoginContainer} />
<Route exact path={Paths.REGISTER} component={RegisterContainer} />
<Route exact path={Paths.PRIVACY} component={Privacy} />
<Route path="*" component={NotFound} />
</Switch>
<Suspense fallback={<AppLoadingView />}>
<Switch {...props}>
<PrivateRoute exact path={Paths.HOME} component={ImagesContainer} isAuthenticated={isAuthenticated} />
<PrivateRoute exact path={Paths.IMAGES} component={ImagesContainer} isAuthenticated={isAuthenticated} />
<PrivateRoute
exact
path={Paths.GET_IMAGES_DETAIL(Paths.ID)}
component={ImagesDetailContainer}
isAuthenticated={isAuthenticated}
/>
<PrivateRoute exact path={Paths.USER} component={UserContainer} isAuthenticated={isAuthenticated} />
<Route exact path={Paths.LOGIN} component={LoginContainer} />
<Route exact path={Paths.REGISTER} component={RegisterContainer} />
<Route exact path={Paths.PRIVACY} component={Privacy} />
<Route path="*" component={NotFound} />
</Switch>
</Suspense>
);

AppRoutes.propTypes = {
Expand Down

0 comments on commit da9e6f8

Please sign in to comment.