Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // We went from using React 0.13 and React Router 0.13 syntax:
- import Router from 'react-router';
- // ...
- app.use('/', (req, res) => {
- let iso = new Iso();
- alt.bootstrap(JSON.stringify(res.locals.data || {}));
- Router.run(routes.server, req.path, (Root, state) => {
- const html = React.renderToString(<Root route={req.path} />);
- iso.add(html, alt.flush());
- res.render('index', {
- app: iso.render(),
- });
- });
- });
- // To using React 0.14 and React Router 2.0 syntax:
- import { match, RouterContext } from 'react-router';
- // ...
- app.use('/', (req, res) => {
- const iso = new Iso();
- alt.bootstrap(JSON.stringify(res.locals.data || {}));
- match({ routes: routes.server, location: req.url }, (error, redirectLocation, renderProps) => {
- if (error) {
- res.status(500).send(error.message);
- } else if (redirectLocation) {
- res.redirect(302, redirectLocation.pathname + redirectLocation.search);
- } else if (renderProps) {
- const html = ReactDOMServer.renderToString(<RouterContext {...renderProps} />);
- iso.add(html, alt.flush());
- res
- .status(200)
- .render('index', {
- app: iso.render(),
- });
- } else {
- res.status(404).send('Not found');
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement