Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SSR with react-router@1.0.0-beta4
// That variant actually works with 1.0.0-beta4
// Link to the previous (1.0.0-beta3) version:
// https://github.com/cdebotton/react-universal/blob/master/src/server.js#L49
import createLocation from 'history/lib/createLocation';
import createHistory from 'history/lib/createMemoryHistory';
import ReactDOM from 'react-dom/server';
import {Router} from 'react-router';
import Layout from './views/Layout';
import Application from './containers/Application';
app.use(function* render() {
const stats = require('../build/webpack-stats.json');
const routes = require('../build/routes-compiled');
const history = createHistory();
const location = createLocation(this.req.url);
const markup = ReactDOM.renderToString(
<Application>
<Router history={history} location={location} routes={routes} />
</Application>
);
const html = ReactDOM.renderToStaticMarkup(
<Layout
markup={markup}
payload={Application.getState()}
{...stats} />
);
this.body = `<!doctype>\n${html}`;
});
@eXon
Copy link

eXon commented Sep 5, 2015

After reading the code of history I'm pretty sure the location prop on Router doesn't exist anymore. You have to do createMemoryHistory(this.req.url) or history.pushState(null, this.req.url)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment