W
W
WizardW2019-07-05 09:56:10
React
WizardW, 2019-07-05 09:56:10

React history push doesn't redirect, no errors, what's wrong?

history.push doesn't redirect.
Connected withRoutes, import withRouter from react-router-dom:

export default withRouter(
  connect(
    mapStateToProps,
    mapDispatchToProps
  )(LoginPageContainer)
);

Dispatch API request and push at the end
const { history } = this.props; 
    if (history) history.push("/messages");

There are no errors, there is history in the container props.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
m_frost, 2019-07-05
@m_frost

get compose from react-redux and try like this

export default compose(
    withRouter,
    connect(mapStateToProps, mapDispatchToProps)(LoginPageContainer)
);

should not be like this
if (history) {
  history.push("/messages");
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question