Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda