this.props.history.push works in some components and not others
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.
The 'this.props.history.push()' is working for normal page but not working for nested components?
Try importing withRouter from 'react-router-dom'
Then pass the component within withRouter
For eg.
export default withRouter(Addmember);
this.props.history.push has undefined state
this.props.history.push({pathname: "adminPage", state : { user : my_user}});
change into
this.props.history.push("/adminPage", { state: user});
Refrence 1
Refrence 2
Related Topics
Pass Variable from Android to JavaScript Launched in Webview
How to Hide Blinking Cursor in Input Text
How to Store Multiple Items in Local Storage
Using Setstate to Change Multiple Values Within an Array of Objects - Reactjs
Show Form Fields Based on Selected Option
Recursively Find Keys on an Object
How to Pass Django Variable into JavaScript
How to Know If Browser Tab Is Already Open Using JavaScript
Fix: Js Recursive Function to Get the Nested (Multilevel) Child Objects as Array of Objects
Calculate String Value in Javascript, Not Using Eval
How to Refresh an Angular Component
Prevent User from Typing in Input At Max Value
How to Resolve Position:Fixed for a Bottom Toolbar on iOS (Iphone/Ipad)
Onchange Event Updates State With 1 Character Delay
How to Open a Web Page Automatically in Full Screen Mode
Export Method/Function in React Native
Looping Through Dynamically Generated Checkboxes to Get Values