实现了 Post-Redirect-Get,现在无法使用后退按钮
我实现了 Post-Redirect-Get 模式,以避免刷新网页为用户提供重新发布数据的机会的问题。
重定向是在服务器端通过 Location 标头和“302 对象已移动”完成的。
只是现在,当我点击后退按钮将表单导航到原始页面(从该页面到达表单)时,一旦我到达帖子页面,它就会重定向,将我向前踢,而不是让我继续返回历史。
有办法解决这个问题吗? javascript: window.location.href = window.location.href
?
重新访问表单,输入新数据并再次发布就可以了。但我希望实际的事后事件本身完全从历史中消失。为什么浏览器甚至会将返回永久重定向的 URL 放入历史堆栈中?
更新
显然我弄错了一些事情。我刚刚测试了 post-redirect-get 的普通情况,后退按钮按预期工作。抱歉浪费了您的时间...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
推荐的重定向方法是使用带有
Location:
标头的HTTP 302 Found
响应。如果您尝试在 Javascript 中执行此操作,
location.replace(url)
会导航到新 URL,同时替换浏览历史记录中的当前 URL。The recommended way to do redirection is an
HTTP 302 Found
response with aLocation:
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.