gpt4 book ai didi

javascript - 使用 HTML5 浏览器历史记录 API 在 SPA 中刷新页面?

转载 作者:行者123 更新时间:2023-11-28 01:35:40 25 4
gpt4 key购买 nike

我不想为我的 SinglePageApplication 使用哈希 URL,而是想使用 HTML5 浏览器历史记录 API。到目前为止效果很好(我正在使用 emberjs )。

哈希 URL 的优点是,我可以刷新页面而不用担心结果。当我尝试使用浏览器历史记录 API 重新加载时,我会收到 404(因为我的服务器没有为此提供的路由)。

那么:是否有一个通用的解决方法来避免这种行为?

我可以告诉我的服务器重定向到索引页面,但这不会向我显示正确的内容。

例子:

GET host/#images
... shows the "images" page (even when it is the index.html)

GET host/images
... redirect to host/
... shows me the content of the index template

最佳答案

https://stackoverflow.com/a/17288940/1423583你的问题的答案?基本上它说您必须更改服务器以始终为 index.html 页面提供服务。

关于javascript - 使用 HTML5 浏览器历史记录 API 在 SPA 中刷新页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28372904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com