Should I use Express Client Response Router or Server Response Router?

I have a simple application that shows a list of user comments. When the user clicks, the application should go to /users/<id>and show a new page with user data that will be requested from MongoDB. I find it difficult to understand where this logic should be.

I saw examples of using a jet router in a client, for example:

render((
<Router>
  <Route path="/" component={App}>
     <Route path="/user/:userId" component={User}/>
  </Route>
</Router>
), document.body)

But also on the server side:

<Route name="root" path="/" handler={require('./handlers/Root')}>

And also using express routing:

app.get('/', function home (req, res, next) {
  res.render('layout', {
    reactHtml: React.renderToString(<App />)
  });
});

app.get('/user', function home (req, res, next) {
  res.render('layout', {
    reactHtml: React.renderToString(<User />)
  });
});

Which one is the way? What are the differences?

+4
source share
2 answers

, node, . , : API, .

, ( JS) SEO (Facebook HTML. . , .

, , , , - . .

, https://github.com/erikras/react-redux-universal-hot-example, .

+2

, , apache php

0

Source: https://habr.com/ru/post/1614451/


All Articles