In testing document.location.href, I have observed that when the user initiates an action that results in javascript that assigns to document.location.href, the new URL is a
URL can be manually added to history before redirecting the user.
if (window.history) { history.pushState({}, window.location.href); } window.location.replace("/login/?next=" + window.location.pathname);