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

194
Visualizações
Passing state by history.push({..}) in TypeScript

I used history.push to redirect to my desired url and passed an information via the included state to the next route like this:

const history = useHistory()
history.push({
   pathname: '/someurl/',
   state: {
      foo: bar
   }
})

and in JavaScript this worked absolutely as expected. Now I am migrating this file to TypeScript and I am getting the following error:

Argument of type '{ pathname: string; state: { foo: bar; }; }'
is not assignable to parameter of type 'To'.

Object literal may only specify known properties, and
'state' does not exist in type 'PartialPath'

For some reason he thinks that I only pass a pathname without a state right? Does anyone know how to fix that?

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

0

Same issue resolved by after trying to fix it I found the problem appears when using custom history, like import history from 'history'; and then <Router history={history}>...</Router> So when I replaced it with <BrowserRouter>...</BrowserRouter> the problem disappeared.

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