Skip to content

Instantly share code, notes, and snippets.

@eiriklv
Forked from aulizko/server.es6.js
Last active September 8, 2015 08:21
Show Gist options
  • Save eiriklv/19be189a195d5c7cc3e2 to your computer and use it in GitHub Desktop.
Save eiriklv/19be189a195d5c7cc3e2 to your computer and use it in GitHub Desktop.
// 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}`;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment