问题
I need to trigger a synchronous action after react-router push, which appears to be async
Is it possible to do something like:
dispatch(push('/', callbackFunction))
I don't see anything in the react-router docs about a callback to push
, which seems quite odd...
回答1:
As it seems, push
is not asynchronous since it is just an action creator (factory pattern).
So you could trigger you actions like this:
dispatch(push('/'));
dispatch(otherAction());
Relevant lines
来源:https://stackoverflow.com/questions/41762677/react-router-push-callback