Skip to content

Instantly share code, notes, and snippets.

@rokoroku
Last active January 2, 2017 02:21
Show Gist options
  • Save rokoroku/090971c580319e4378c130c07280f796 to your computer and use it in GitHub Desktop.
Save rokoroku/090971c580319e4378c130c07280f796 to your computer and use it in GitHub Desktop.
react-router-v3-lazy
// lazy load helper
function lazyComponent(promise: Promise<any>): (nextState: Router.RouterState, callback: (error, component?) => void) => void {
return (nextState, callback) => {
promise.then(
(module) => {
setTimeout(() => callback(null, module.default) && router.setLoading(true), 1000)
},
(error) => callback(error)
);
}
}
// render react DOM
ReactDOM.render(
<Provider {...rootStores} >
<Router history={browserHistory} >
<Route path='/' component={BaseContainer}>
<IndexRedirect to={PATH_LOGIN} />
<Route path={PATH_LOGIN} getComponent={lazyComponent(System.import('app/containers/Login'))} />
<Route path={PATH_SIGNUP} getComponent={lazyComponent(System.import('app/containers/Signup'))} />
</Route>
</Router>
</Provider >,
document.getElementById('root')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment