23 lines
No EOL
558 B
Markdown
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);
|
|
};
|
|
|
|
``` |