私はサーバー側のレンダリングのアプリを持っています。ここでは、サーバー側のコードは次のとおりです。サーバーサイドレンダリングを行う前に、どのようにアクションを自分の店にディスパッチできますか? - Redux
export default (req, res, next) => {
const store = getStore();
// HERE IS THE DISPATCH
getStore().dispatch(updateToken("TOKEN"));
match({ routes, location: req.url }, (err, redirect, props) => {
if (err) {
return next(err);
} else if (redirect) {
res.redirect(redirect.pathname + redirect.search)
} else if (props) {
resolveAsyncDeps(store, props)
.then(() => {
//HERE IS INITIAL STATE
const initialState = store.getState();
const content = renderToString(
<Provider store={store}>
<RouterContext {...props} />
</Provider>
);
res.send(
minify(
docTemplate({
...(Helmet.rewind()),
content,
initialState,
env: { DASHBOARD_REST_API, DASHBOARD_WS_API }
}),
{ collapseWhitespace: true, removeAttributeQuotes: false }
)
);
}).catch(next);
} else {
res.status(404).send('Not Found')
}
})
}
私のアクションが同期している:私store
のgetState()
がinitialState
として伝承する際
export function updateToken(token) {
return {
type: UPDATE_TOKEN,
payload: {
token
}
};
}
しかし、私のtoken
は状態ツリーではありません。 thunk
などのミドルウェアを使用していない限り、dispatch
は同期していたと思いますか?私は何が欠けていますか?フロントエンドにプッシュする前に、initialState
に何かを追加するにはどうすればよいですか?