Prevent sort2Hash from adding extraneous entries to browser history

Use `window.location.replace` to update the browser URL only, rather than `window.location.hash`, which modifies the browser history.
This commit is contained in:
Alex Weissman 2017-08-12 17:10:09 -04:00 committed by Rob Garrison
parent 86e2b7c355
commit 6fe2cdf810

View File

@ -225,8 +225,19 @@
hash = s2h.cleanHash( c, wo, component, hash );
str += value;
});
// add updated hash
window.location.hash = ( ( window.location.hash || '' ).replace( '#', '' ).length ? hash : wo.sort2Hash_hash ) + str;
// Combine new hash with any existing hashes
var hashChar = c.widgetOptions.sort2Hash_hash;
var newHash = ( ( window.location.hash || '' ).replace( hashChar, '' ).length ? hash : wo.sort2Hash_hash ) + str;
var baseUrl = window.location.href.split(hashChar)[0];
// Ensure that there is a leading hash character
var firstChar = newHash[0];
if (firstChar != hashChar) {
newHash = hashChar + newHash;
}
// Update URL in browser
window.location.replace(baseUrl + newHash);
}
};