React router v4 - How do you access the state that is passed via Redirect?
you can access state using this.props.location.state
If you're using React hooks you can use useLocation
hook.
import { useLocation } from 'react-router-dom';
export const MyComponent = () => {
const { state } = useLocation();
...
}
You can use the location
prop to access the state you have passed. Visit React-Router for reference. When you want to access that state, you can do it by this.props.location.state
.