-
-
Save eiriklv/19be189a195d5c7cc3e2 to your computer and use it in GitHub Desktop.
SSR with [email protected]
This file contains hidden or 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
| // 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