Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
HashRouter not working with useLocation()

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!