I am trying to pass props via history.push, but location.state is undefined in the next component. Interestingly, I can pass a value using hash and search, just not state. The initial component is a functional one that imports useHistory via react-router-dom and initializes it using useHistory(), and the next component is a class and am importing withRouter and have wrapped the export.
I am using React Router v5.2.0, and my code looks like:
const location = {
pathname: `/dashboard`,
state: { detail: 'test' }
}
history.push(location);
And in the next component, I am trying to access the detail props as follows:
let detail = this.props.location.state;
this.props.history.location.state is also undefined.
I would appreciate any help with this, thanks!