在页面刷新时使用 Angular JS ui.router html5Mode(true) 配置 Amazon S3 静态站点 [英] Configure Amazon S3 static site with Angular JS ui.router html5Mode(true) on page refresh

查看:22
本文介绍了在页面刷新时使用 Angular JS ui.router html5Mode(true) 配置 Amazon S3 静态站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何配置 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.

https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

然而,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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆