Appending parameter to URL without refresh
https://stackoverflow.com/questions/32828160/appending-parameter-to-url-without-refresh
Appending parameter to URL without refresh
I know this has been asked many times before but answers were not descriptive enough to solve my problem. I don't want to change the whole URL of page. I want to append a parameter &item=brand on
stackoverflow.com
앱에서 refresh없이 url만 바꿔야하는 일이 있어서 찾아봤더니 위의 글이 좋았다.
- History.pushState
https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
History.pushState() - Web APIs | MDN
In an HTML document, the history.pushState() method adds an entry to the browser's session history stack.
developer.mozilla.org
- History.replaceState
https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState
History.replaceState() - Web APIs | MDN
The History.replaceState() method modifies the current history entry, replacing it with the stateObj, title, and URL passed in the method parameters. This method is particularly useful when you want to update the state object or URL of the current history
developer.mozilla.org
History.pushState의 상세 설명을 보면 아래와같다.
pushState를 부르는건 hash를 업데이트하는것과 비슷하다. 그런데 window.location으로 조작하면 hash값을 변경할때만 동일한 문서에 남아있도록 하는데, pushState를 쓰면 여전히 동일한 문서에 있을 수 있다.