Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
useNavigate hook not working in React router

I have two pages, Dashboard and Quiz. Dashboard triggers an event which calls the useNavigate function with the state.

const nav = useNavigate();
const goToTest = (e)=>{

    e.preventDefault()

    nav('/student/Quiz',{state:{id:1}});
  }

In quiz, I then use useLocation to try and get the data but it doesn't seem to work.

function Quiz() {
  const {data} = useLocation();
  console.log(data);

If i don't destructure data in quiz, it shows some json data, but state is always null

hash: ""
key: "(a key was here)"
pathname: "/student/Quiz" (Dashboard and quiz are both in the same directory as student)
search: ""
state: null
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Turns out it was a version issue. This happened on 6.14 but when I updated it to 6.2 it works fine.

The docs had mentioned v6 and above, so I thought I was in the clear.

I'll leave this question up for anyone who gets the same issue.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda