Skip to content

Instantly share code, notes, and snippets.

@gonzalovazquez
Created September 21, 2018 20:54
Show Gist options
  • Save gonzalovazquez/31c4087f7304ed43326c5528027ee12b to your computer and use it in GitHub Desktop.
Save gonzalovazquez/31c4087f7304ed43326c5528027ee12b to your computer and use it in GitHub Desktop.
Server Side Routing in React
/**
* 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