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

75
Visualizações
How do you pass data when using the navigate function in react router v6

In v4 you would do a history.push('/whatever', { data }) Then the component tied to that route could read the data object by referencing the history.location.state

Now with v6 that's changed to navigate('whatever')

How do you pass data like before?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It's similar to how it's done in v4, two arguments, the second being an object with a state property.

navigate(
  'thepath',
  {
    state: {
      //...values
    }
  }
})

From the migration guide: Use navigate instead of history

If you need to replace the current location instead of push a new one onto the history stack, use navigate(to, { replace: true }). If you need state, use navigate(to, { state }). You can think of the first arg to navigate as your and the other arg as the replace and state props.

To access the route state in the consuming component use the useLocation React hook:

const { state } = useLocation();
about 4 years ago · Juan Pablo Isaza 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