joplin-notes/joplin notion extension/Web Development/React/Tips/Change parameters of URL without refreshing it.md
2026-11-04 00:33:23 +05:30

558 B

Change parameters of URL without refreshing it

const changeURLParams = (newValue) => {
  const newURL = `${window.location.pathname}${newValue}`;

  window.history.pushState({ path: newURL }, "", newURL);
};

Change queries of URL without refreshing it

const changeQueryParams = () => {
  const urlParams = new URLSearchParams(window.location.search);
  urlParams.set('queryParamName', 'newValue');

  const newURL = `${window.location.pathname}?${urlParams.toString()}`;

  window.history.pushState({ path: newURL }, '', newURL);
};