Created
May 4, 2016 14:15
-
-
Save jonykrause/a267165df4dd7689575511b6e65215fd to your computer and use it in GitHub Desktop.
universal react-router
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
// SHARED | |
const routes = ( | |
<Route path="/base" component={Layout}> | |
<IndexRoute component={A} /> | |
<Route path="/base/foo" component={B} /> | |
<Route path="*" component={C} /> | |
</Route> | |
); | |
// SERVER | |
// render.js | |
const memoryHistory = createMemoryHistory(req.url); | |
const history = syncHistoryWithStore(memoryHistory, store); | |
match({ history, routes, location: req.originalUrl }, (err, redirectLocation, renderProps) => { | |
res.send(renderPage(content, store)); | |
}); | |
//server.js | |
express().use("/base", render.js) | |
// CLIENT | |
const history = syncHistoryWithStore(browserHistory, store); | |
render( | |
<Provider store={store}> | |
<Router history={history} routes={routes} /> | |
</Provider>, | |
document.getElementById("app") | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Besides that (Basename is something I could not get to work by trying to enable it server side with
const memoryHistory = useRouterHistory(createMemoryHistory)({ entries: ["/"], basename: "/base" });
leads to<a href="/base/base">
in html