实现了 Post-Redirect-Get,现在无法使用后退按钮

发布于 2024-11-25 13:04:28 字数 461 浏览 0 评论 0原文

我实现了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贱贱哒 2024-12-02 13:04:28

推荐的重定向方法是使用带有 Location: 标头的 HTTP 302 Found 响应。

如果您尝试在 Javascript 中执行此操作,location.replace(url) 会导航到新 URL,同时替换浏览历史记录中的当前 URL。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文