javascript - How to setup server side rendering with react-router 2 -


i want port app react-router 2.0 1.0. trying server side rendering on express.

server.js code (1.0) (working)

var routes = require('./public/js/app.node.js');  app.get('*', function(req, res, next) {    var location = new location(req.path, req.query);    try {     router.run(routes(), location, function(e, i, t) {       var str = react.rendertostring(                   react.createelement(router, i));     });   } catch(e) {     return next();   } }); 

server.js code (2.0) (not working)

var routes = require('./public/js/app.node.js');  app.get('*', function(req, res, next) {    var location = new location(req.path, req.query);    try {   match({routes, location: req.url} , function (error, redirectlocation, renderprops) {       if (error) {         res.status(500).send(error.message);       } else if (redirectlocation) {         res.redirect(302, redirectlocation.pathname + redirectlocation.search);       } else if (renderprops) {         var str = rendertostring(react.createelement(routingcontext, renderprops));         res.status(200).send(str);       } else {         res.status(404).send('not found');       }   }); } 

routes.jsx:

  export default (withhistory, onupdate) => {    return (     <provider store={store}>       <router history={history} onupdate={onupdate}>         <route path='/' component={barcodelisting} />       </router>     </provider>   ); }; 

the above code not match /. why that. console.log(req.url) gives me /, / in routes should match / in req.url right !!


Comments