Last active
January 2, 2017 02:21
-
-
Save rokoroku/090971c580319e4378c130c07280f796 to your computer and use it in GitHub Desktop.
react-router-v3-lazy
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
// 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