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

199
Visualizações
React-router: is there a way to use push from history to append a query string after this current path?

my current URL is /foo and I want to add a query string to it i.e. /foo?date=2022-02-15

The way I did is location.search = queryString and it works but it results in a full reload. I wanted to use History API from react-router so I can avoid the full reload.

But history.push is going to replace the whole path /foo with date=2022-02-15 (so the URL is going to be date=2022-02-15 as opposed to /foo?date=2022-02-15) as it doesn't append ?date=2022-02-15 to the current path /foo like location.search would do. So is there a way to use history API to achieve the same behavior?

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

0

You can get the current pathname from the location object of the current route being matched and rendered.

Example:

const location = useRouteMatch();
const queryString = "date=2022-02-15";

...

// as a string
history.push(`${location.pathname}?${queryString}`);

// or as an object
history.push({
  pathname: location.pathname,
  search: `?${queryString}`,
});
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