Skip to content

Instantly share code, notes, and snippets.

@javarouka
Last active June 6, 2017 15:42
Show Gist options
  • Save javarouka/6e00543ef5a30fd6ae044fbeae61af0e to your computer and use it in GitHub Desktop.
Save javarouka/6e00543ef5a30fd6ae044fbeae61af0e to your computer and use it in GitHub Desktop.
createAsyncRoute.js
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