Last active
March 10, 2016 07:19
-
-
Save GriffinHeart/e25950dc270da0bb1577 to your computer and use it in GitHub Desktop.
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
//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