Skip to content

Commit

Permalink
Changes the client side router configuration to handle redirect and "…
Browse files Browse the repository at this point in the history
…no renderProps" cases. Fixes mui#29
  • Loading branch information
ctrlplusb committed Jul 24, 2016
1 parent 6424c8b commit 17a3531
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/client/index.js
Expand Up @@ -9,27 +9,36 @@ import routes from '../shared/routes';
// Get the DOM Element that will host our React application.
const container = document.querySelector('#app');

function routerError(error) {
// TODO: Error handling.
console.error('==> 😭 React Router match failed.'); // eslint-disable-line no-console
if (error) { console.error(error); } // eslint-disable-line no-console
}

function renderApp() {
// As we are using dynamic react-router routes we have to use the following
// asynchronous routing mechanism supported by the `match` function.
// @see https://github.com/reactjs/react-router/blob/master/docs/guides/ServerRendering.md
match({ history: browserHistory, routes }, (error, redirectLocation, renderProps) => {
if (error) {
// TODO: Error handling.
console.log('==> 😭 React Router match failed.'); // eslint-disable-line no-console
routerError(error);
} else if (redirectLocation) {
return;
} else if (renderProps) {
render(
<AppContainer>
{/*
We need to explicly render the Router component here instead of have
this embedded within a shared App type of component as we use different
router base components for client vs server rendering.
*/}
<Router {...renderProps} />
</AppContainer>,
container
);
} else {
routerError();
}

render(
<AppContainer>
{/*
We need to explicly render the Router component here instead of have
this embedded within a shared App type of component as we use different
router base components for client vs server rendering.
*/}
<Router {...renderProps} />
</AppContainer>,
container
);
});
}

Expand Down

0 comments on commit 17a3531

Please sign in to comment.