我有一个简单的应用程序,它显示用户的评论列表。当单击用户时,应用程序应该转到/users/<id>
并显示一个新页面,其中包含将从 MongoDB 查询的用户详细信息。我很难理解该逻辑应该在哪里。
我看到了在客户端中使用 react 路由器的示例,例如:
render((
<Router>
<Route path="/" component={App}>
<Route path="/user/:userId" component={User}/>
</Route>
</Router>
), document.body)
但在服务器端也是这样:
<Route name="root" path="/" handler={require('./handlers/Root')}>
并且还使用快速路由:
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 />)
});
});
哪一个是要走的路?有什么区别?