I'm trying to use useLocation() but it is not working with HashRouter
I have a component that send some data to another route
const onSubmit = () => {
if (index < questions[selected].length - 1) {
setIndex((value) => value + 1);
} else {
history.push("/final", { selected, answer });
}
};
And on the route I have:
const { state } = useLocation();
const { selected, answer } = state;
But when I try to run the application it gives me the error:
TypeError: Cannot destructure property 'selected' of 'state' as it is undefined.
What am I doing wrong?
From https://v5.reactrouter.com/web/api/HashRouter:
IMPORTANT NOTE: Hash history does not support location.key or location.state.
Hence location.state is undefined with HashRouter