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

23 lines
No EOL
558 B
Markdown

Change parameters of URL without refreshing it
```jsx
const changeURLParams = (newValue) => {
const newURL = `${window.location.pathname}${newValue}`;
window.history.pushState({ path: newURL }, "", newURL);
};
```
Change queries of URL without refreshing it
```jsx
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);
};
```