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? –