I implemented the Post-Redirect-Get pattern to avoid the problem where a refresh of a web page offers the user the chance to repost the data.
The redirect is being accomplished server-side with the Location header and "302 Object moved".
Only now, when I hit the back button to navigate past the form to the original page (from which the form was reached), as soon as I land on the post page it redirects, kicking me forward instead of letting me keep going back in the history.
Is there a way around this? javascript: window.location.href = window.location.href
?
Revisiting the form, entering new data and posting again is fine. But I'd like the actual post event itself to just fall out of history entirely. Why do browsers even put into the history stack URLs that return a permanent redirect?
Update
Apparently I am mistaken about something. I just tested a plain vanilla case of post-redirect-get and the back button works as expected. Sorry to have wasted your time...
The recommended way to do redirection is an HTTP 302 Found
response with a Location:
header.
If you're trying to do it in Javascript, location.replace(url)
navigates to a new URL while replacing the current URL in the browsing history.