When redirecting a form with a redirect input, for example
<input type="hidden" name="redirect" value="<url>">
the browser may preserve the window hash after the redirect. For example, submitting
<form>
<input type="hidden" name="redirect" value="my-other-page">
<button type="submit">
</form>
from mydomain.com/my-page#my-hash
may take the user to mydomain.com/my-other-page#my-hash
.
That isn't always desirable; for example it isn't uncommon to need to redirect to the top of another page, where a confirmation message may be shown. To do that, take the hash out of the current page before submitting the form:
myForm.addEventListener('submit', () => {
window.history.pushState(null, '', window.location.pathname)
}
now submitting the above form from mydomain.com/my-page#my-hash
should reliably take the user to mydomain.com/my-other-page
.