Skip to content

Instantly share code, notes, and snippets.

@GriffinHeart
Last active March 10, 2016 07:19
Show Gist options
  • Save GriffinHeart/e25950dc270da0bb1577 to your computer and use it in GitHub Desktop.
Save GriffinHeart/e25950dc270da0bb1577 to your computer and use it in GitHub Desktop.
//client side
const { pathname, search, hash } = window.location;
const location = `${pathname}${search}${hash}`;
match({ routes, location }, (error, redirectLocation, renderProps) => {
console.log(renderProps);
console.log(location);
render(
<Provider store={store}>
<ContextHolder context={context}>
<Router {...renderProps} children={routes} history={Location} />
</ContextHolder>
</Provider>,
appContainer
);
});
//server side
match({ routes, location: req.url }, (error, redirectLocation, renderProps) => {
data.body = ReactDOM.renderToString(
<Provider store={store}>
<ContextHolder context={context}>
<RouterContext {...renderProps} />
</ContextHolder>
</Provider>
);
data.css = css.join('');
res.status(statusCode);
res.send(template(data));
});
// routes
async function getContextComponent(location, callback) {
const response = await fetch(`/api/content?path=${location.pathname}`);
const content = await response.json();
callback(null, () => <ContentPage {...content} />);
}
export default (
<Route>
<Route path="/" component={App} >
<IndexRoute component={Dashboard} />
<Route path="about" getComponent={getContextComponent} />
</Route>
<Route path="*" component={NotFoundPage} />
</Route>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment