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

215
Visualizações
How to remove the query parameters from the URL once the page loads and the function that requires them goes through?

I have the following situation:

I'm on page A which has a call button that redirects the user to page B with URL /calls?id=1234

On page B's componentDidMount(), I want to get the query parameter, use it and then remove it from the URL so that the componentDidMount() does not execute the function again on refresh. Right now I have the following piece of code:

componentDidMount() {
    const qParams = new URLSearchParams(window.location.hash.split('?')?.pop());

    if (qParams.has('id')) {
        this.initiateCall(new DiallerRoomUser(
            DiallerRoomUserType.matrix,
            getLocalUserIdFromUserId(qParams.get('id')),
        ));
        qParams.delete('id');
        const url = new URL(window.location);
        url.hash = '#/calls';
        window.history.pushState({}, '', url);
    }
}

The URL I'm working with looks like this:

https://127.0.0.1:8080/#/calls?id=test

I believe I gotta use history.pushState but what happens with my code right now is the following:

  • I click the button on page A that redirects me to page B.
  • I get to page B and the componentDidMount() code executes correctly BUT the URL doesn't change.
  • I refresh the page once, componentDidMount() code executes again but this time the URL changes to the correct one.
about 4 years ago · Juan Pablo Isaza
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