JSFiddle - React, Tailwind, and code Playground
HTML
<button id="remove" disabled>Remove Hash</button>
<a href="#hash">Click for hash</a>
JavaScript
var btn = document.getElementById("remove");
btn.disabled = !(location.hash || location.href.slice(-1) == "#");
btn.onclick = removeHash;
window.onhashchange = function () {
btn.disabled = !(location.hash || location.href.slice(-1) == "#");
}
function removeHash() {
window.history.pushState("", document.title, window.location.pathname);
btn.disabled = !(location.hash || location.href.slice(-1) == "#");
}