top of page

Javascript - Update URL query string without refreshing the page

Foto do escritor: Fábio HenriqueFábio Henrique

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.

4.904 visualizações0 comentário

Posts recentes

Ver tudo

React básico

Comments


bottom of page