Last active
June 6, 2017 15:42
-
-
Save javarouka/6e00543ef5a30fd6ae044fbeae61af0e to your computer and use it in GitHub Desktop.
createAsyncRoute.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { Route } from 'react-router-dom' | |
import { routes } from './routeMap' | |
import Bundle from 'component/bundle/Bundle' | |
import LoadingIndicator from 'component/bundle/LoadingIndicator' | |
const AsyncRoute = ({ component: Component, store, ...rest }) => ( | |
<Route {...rest} render={props => ( | |
<Bundle store={store} load={Component}> | |
{(Component) => { | |
return Component ? <Component {...props} /> : <LoadingIndicator />; | |
}} | |
</Bundle> | |
)}/> | |
); | |
export const renderRoutes = store => ( | |
routes.map((route, index) => ( | |
<AsyncRoute | |
key={index} | |
store={store} | |
path={route.path} | |
exact={route.exact} | |
component={route.component} | |
/> | |
)) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment