【发布时间】:2016-02-05 00:06:09
【问题描述】:
我有一个简单的应用程序,它显示用户的 cmets 列表。单击用户时,应用程序应转到 /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 />)
});
});
哪一个是要走的路?有什么区别?
【问题讨论】:
-
您是如何决定这样做的?我不确定 React Router 和 Express 应该如何协同工作。
标签: node.js express reactjs react-router isomorphic-javascript