Skip to content

Instantly share code, notes, and snippets.

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:
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(
<Router history={history} location={location} routes={routes} />
const html = ReactDOM.renderToStaticMarkup(
{...stats} />
this.body = `<!doctype>\n${html}`;
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