在页面刷新时使用 Angular JS ui.router html5Mode(true) 配置 Amazon S3 静态站点 [英] Configure Amazon S3 static site with Angular JS ui.router html5Mode(true) on page refresh
问题描述
如何配置 Amazon S3 静态网页以正确路由 Angular ui.router html5Mode 路由?在页面刷新时,它会请求一个不存在的文件,而 angular 无法处理它.在文档中,他们建议更改服务器上的 URL 重写.
How can I configure an Amazon S3 static webpage to properly route Angular ui.router html5Mode routes? On page refresh, it will make a request for a file that doesn't exist, and angular can't handle it. In the docs, they recommend changing your URL rewrites on the server.
然而,S3 是存储,不提供相同的重定向选项我一直在尝试使用内置的重定向规则,例如
However, S3 is storage, and doesn't offer the same redirection options I have been trying to use the built in redirection rules such as
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals >
</Condition>
<Redirect>
<HostName>[[ your application's domain name ]]</HostName>
<ReplaceKeyPrefixWith>#/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
然而,这只会导致重定向循环.
However, this just leads to a redirect loop.
有什么建议吗?
推荐答案
基本上有 3 个选项,使用 EC2 实例对配置的 HTML5 路由执行实际服务器重写,或者像 dnzay 建议的那样,使用回退模式和重写请求以使用 #!哈希棒.最后,您可以只使用标准的角度路线,这是我选择的选项.更少的麻烦,当 Angular 2.0 推出时,您可以更新到它.
Basically there are 3 options, use an EC2 instance to perform the actual server rewrites to the configured HTML5 routes, or, like dnozay suggested, use the fallback mode and re-write requests to use the #! hashbang. Finally, you could just use the standard angular routes, which is the option I went with. Less hassle, and when Angular 2.0 rolls around, you can update to that.
https://stackoverflow.com/a/16877231/1733117
这里并没有真正解决路由问题.
Doesn't really address the routing issue here.
这篇关于在页面刷新时使用 Angular JS ui.router html5Mode(true) 配置 Amazon S3 静态站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!