top of page

Javascript - Update URL query string without refreshing the page

  • Foto do escritor: Fábio Henrique
    Fábio Henrique
  • 18 de jan. de 2022
  • 1 min de leitura

In order to update the query string of an URL without reloading the page, we can use the history.pushState() method.


This method receives 3 parameters (state, title, url), only the last matter for this post


const url = new URL(window.location);
url.searchParams.set('podcast', 'ninjaDevCast');
window.history.pushState({}, '', url);

Execute the code above in your browser console in order to see it working.

Nunca perca um post. Assine agora!

Fique sempre por dentro das dicas ninjas de programação com o uso de stacks poderosas como React, Angular, NetCore e muito mais!

© 2020 por equipe DevNinja.

  • Facebook
  • Twitter
Ativo 4.png
bottom of page