Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. // We went from using React 0.13 and React Router 0.13 syntax:
  2. import Router from 'react-router';
  3. // ...
  4.  
  5. app.use('/', (req, res) => {
  6. let iso = new Iso();
  7. alt.bootstrap(JSON.stringify(res.locals.data || {}));
  8.  
  9. Router.run(routes.server, req.path, (Root, state) => {
  10. const html = React.renderToString(<Root route={req.path} />);
  11. iso.add(html, alt.flush());
  12.  
  13. res.render('index', {
  14. app: iso.render(),
  15. });
  16. });
  17. });
  18.  
  19. // To using React 0.14 and React Router 2.0 syntax:
  20. import { match, RouterContext } from 'react-router';
  21. // ...
  22.  
  23. app.use('/', (req, res) => {
  24. const iso = new Iso();
  25. alt.bootstrap(JSON.stringify(res.locals.data || {}));
  26.  
  27. match({ routes: routes.server, location: req.url }, (error, redirectLocation, renderProps) => {
  28. if (error) {
  29. res.status(500).send(error.message);
  30. } else if (redirectLocation) {
  31. res.redirect(302, redirectLocation.pathname + redirectLocation.search);
  32. } else if (renderProps) {
  33. const html = ReactDOMServer.renderToString(<RouterContext {...renderProps} />);
  34.  
  35. iso.add(html, alt.flush());
  36. res
  37. .status(200)
  38. .render('index', {
  39. app: iso.render(),
  40. });
  41. } else {
  42. res.status(404).send('Not found');
  43. }
  44. });
  45. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement