I have the following Router:
root.render(
<Router history={history}>
<Routes>
<Route path='/Page1' element={<Page1/>} />
<Route path='/Page2' element={<Page2/>} />
</Routes>
</Router>
);
Page1 & Page2 are both class components. I'm trying to send the state from /Page1 to /Page 2 using the Link component in React-Router v6. The props I want to send is an object called "participant" available in /Page1.
I have followed this example, but it returns the following error:
Cannot read properties of undefined (reading 'state') at Page2.componentDidMount (Page2.js:142:1)
///////////// Page1
let myParticipant = this.retrieveParticipant(uniqueId); // this function retrieves an object
//...
<Link to="/EditCandidates" state={{myParticipant}} className="btn btn-primary">Edit Candidate</Link>
///////////// Page2
const {myParticipant} = this.props.location.state;
Someone here remarked that in react-router v6 it only works using useLocation() and that the this.props.location.state is no longer working.
Is there any way to do this in react-router V6 without changing from class component to functional component?