Created
September 21, 2018 20:54
-
-
Save gonzalovazquez/31c4087f7304ed43326c5528027ee12b to your computer and use it in GitHub Desktop.
Server Side Routing in React
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
/** | |
* Async IIFE React | |
* Renders Spinner then tries to fetch routes from server. | |
* If routes are not available it renders application | |
* with default routes. | |
*/ | |
(async () => { | |
ReactDOM.render(<ProgressBar />, elementMountPoint); | |
try { | |
const newContext = { | |
store, | |
routes: dynamicRoutes(context.routes, await fetchMenuByHost()), | |
}; | |
ReactDOM.render(<App context={newContext} />, elementMountPoint); | |
} catch (e) { | |
ReactDOM.render(<App context={context} />, elementMountPoint); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment