常规链接以及使用 Pushstate 和 PopState 的问题
这就是我的流程的运作方式。用户单击链接 - “find”,然后显示一个使用 ajax 的页面。我使用 pushState
添加到历史记录。然后,用户单击“下一步”查看第 2 页的结果(使用 ajax),我再次添加推送状态。所以,当用户返回时,这工作得很好。但是,我的问题是,假设用户位于结果的第 2 页,并单击常规链接(即没有 ajax 调用)。他被带到一个新页面,但当他点击返回时,他不会被带到结果页面 2,而是被带到初始搜索页面。
这是正常行为吗?或者可以做点什么吗?
This is how my flow works. User clicks on a link - "find", and is shown a page using ajax. I add to history using pushState
. Then, the user clicks next to see results of page 2(using ajax), and I add again to push state. So, this works fine, when the user goes back. But, my issue is that say user is on page 2 of results, and clicks a regular link(i e no ajax call). He is taken to a new page, but when he clicks back, he is not taken to results page 2 but to the initial search page.
Is this normal behavior? Or can something be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您的搜索/结果页面在加载时没有正确更新其状态。当您从“常规页面”返回时,“ajax 页面”将重新加载,从而丢失其状态。您必须手动恢复状态(例如读取url并执行相应的ajax)。
Sounds like your search/result page is not properly updating its state when loaded. When you go back from "regular page", the "ajax page" is reloaded and thus loses its state. You must manually restore the state (e.g. read the url and doing the corresponding ajax).