App.jsにリンクがあります - 私はアクションクリエイター/レデューサーが必要かどうかわかりませんか?もしそうなら、それをサーバーサイドのレンダリングでワイヤリングする方法はありますか?シンプルなサーバー/クライアントルーティングreact-express(nodejs)
基本的にはotherComponentの読み込み時に、pathで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/gregartemides-これはサーバー側のレンダリング用です。申し訳ありませんが私の質問が明確でない場合。 – monkeyjs
ああ...あなたはnextjs https://github.com/zeit/next.js/を試しましたか? –
ちょうど私が正しく理解していることを確認する - あなたは、エクスプレスに構築されたAPIを持っていて、あなたのクライアントアプリケーションはReactであり、それを提供する前にReactをレンダリングしたいですか? –