this.props.history.push works in some components and not others

You Can try this

this.context.history.push('/dashboard')

or pass the history as a prop from parent to child component like

parent

<SignupForm history={this.props.history}/>

child

this.props.history.push('/dashboard');

or withRouter

import { withRouter } from "react-router";
export default withRouter(connect(mapStateToProps, {
    ...
})(Header));

You answered your question in your question.

As you can see, the components are virtually exactly the same except that the child one is inside the parent one.

The very fact that the component is nested one further is your issue. React router only injects the routing props to the component it routed to, but not to the components nested with in.

See the accepted answer to this question. The basic idea is that you now need to find a way to inject the routing props to the child component. You can do that by wrapping the child in a HOC withRouter.

export default withRouter(connect(mapStateToProps, matchDispatchToProps)(ChildView));

I hope this helps.


Using withRouter is fine, an alternative option is to pass the history as a prop from parent to child (without using withRouter), e.g:

Parent

<SignupForm history={this.props.history}/>

Child

this.props.history.push('/dashboard');