Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!