App.js有一个链接 - 我不理解我是否需要动作创建者/缩减器?如果是的话,如何将它与服务器端渲染连接起来?简单的服务器/客户端路由react-express(nodejs)
基本上在其他组件的负载 - 应通过路径从server.js进行API调用并将响应注入组件 - 响应动作在哪里适合此图片?
server.js:
app.get('/test', (req, res) => {
res.send(<otherComponent />); -> this is returning json right now? How to handle this path for example here - where this should make an api call.
});
app.get('*', (req, res) => {
res.send(`
<!doctype html>
<html>
<head>
<title>My website</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id='app'>${renderToString(
<Provider store={createStore(reducers)}>
<StaticRouter location={req.url} context={{}}>
<App />
</StaticRouter>
</Provider>
)}</div>
<script src='bundle.js'></script>
</body>
</html>
`);
});
@https://stackoverflow.com/users/2885592/greg-artemides - 这是服务器端渲染......对不起,如果我的问题不清楚。 – monkeyjs
哦......你有没有尝试过nextjs https://github.com/zeit/next.js/? –
只是为了确保我理解正确 - 你有一个建立在Express上的api,你的客户端应用程序是React,并且你想在服务器之前渲染服务器上的React? –