Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda