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

341
Visualizações
How to pass parameters with React-router-dom version 6 useNavigate and typescript

I am trying to send the variable id to another page using useNavigate in react-router-dom version 6. Here is what I am trying:

const handleSelect = (id: number) => {
    navigate('/Players', {
      userId: id,
    });
  };

However I I am getting the error: Argument of type '{ userId: number; }' is not assignable to parameter of type 'NavigateOptions'. Object literal may only specify known properties, and 'userId' does not exist in type 'NavigateOptions'.ts(2345)

I can't find any useful information on NavigateOptions or what type it is looking for. If I remove the parameter userId then I can navigate to the Player page just fine. It is just the parameter that is causing the problem. What can I do about this issue? Could someone provide some documentation on this?

What would be an example of a parameter that is of type NavigateOptions?

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

0

Did you mean to add state to the navigation? Original:

const handleSelect = (id: number) => {
    navigate('/Players', {
      userId: id,
    });
  };

Changed to (with state):

const handleSelect = (id: number) => {
    navigate('/Players', {
      state: {
        userId: id,
      }
    });
  };

Then you can reference props.location.state.userId in the Players page.

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