Skip to content

Instantly share code, notes, and snippets.

@mohandere
Created March 11, 2018 11:34
Show Gist options
  • Save mohandere/2af998f8b9faa3957e136ff6c538f53a to your computer and use it in GitHub Desktop.
Save mohandere/2af998f8b9faa3957e136ff6c538f53a to your computer and use it in GitHub Desktop.
asyncRoutes in CRA
import React from 'react';
import {
Route,
Switch
} from 'react-router';
import Loadable from 'react-loadable';
import AppLoader from './common/components/AppLoader';
// Import modules/routes
import About from './about';
import PageNotFound from './common/components/PageNotFound';
// Code splitting with dynamic import
// https://reactjs.org/docs/code-splitting.html
const Home = Loadable({
loader: () =>
import ('./home'),
loading: AppLoader
});
export default (
<Switch>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="*" component={PageNotFound} />
</Switch>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment