Skip to content

Commit

Permalink
change hash without affecting the rest of URL (#9960)
Browse files Browse the repository at this point in the history
* change hash without affecting the rest of URL

Closes #9955 . Hash change currently replaces history state url with only the updated hash, ignoring the current URL (path, query parameters etc). This PR fixes the hash change method, so that it updates only the fragment (part in case of a named fragment parameter), while leaving the rest of URL untouched.

* bump the branch to try to trigger Circle CI

* use null in place of document.title

null will default to document.title

Co-authored-by: Vladimir Agafonkin <agafonkin@gmail.com>
  • Loading branch information
raegen and mourner authored Sep 1, 2020
1 parent 476ce36 commit eb64a62
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ui/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ class Hash {
}

_updateHashUnthrottled() {
const hash = this.getHashString();
// Replace if already present, else append the updated hash string
const location = window.location.href.replace(/(#.+)?$/, this.getHashString());
try {
window.history.replaceState(window.history.state, '', hash);
window.history.replaceState(window.history.state, null, location);
} catch (SecurityError) {
// IE11 does not allow this if the page is within an iframe created
// with iframe.contentWindow.document.write(...).
Expand Down

0 comments on commit eb64a62

Please sign in to comment.