hsz hsz - 1 year ago 85
React JSX Question

Redirect to another route when `mapHooks` fails

I have defined following


const mapHooks = {
fetch: ({ dispatch, params }) => dispatch(fetchPost(params.postId)).catch(() => {

Sometimes, post cannot be found and I'd like to redirect user to the another page.
When I
the error I tried to call
to redirect to
page, but it does nothing (
comes from

How can I redirect user properly ?

Answer Source

push function that comes with react-router-redux is an action creator, meaning that it returns an action that you need to dispatch. So you need to call it like this: dispatch(push('/foo'))

Also, check if you have your routerMiddleware installed correctly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download