Angular 在 S3 上,刷新导致 "AccessDenied" 响应

Angular on S3, refresh causes "AccessDenied" response

我有一个 angular 5 应用程序 - 我已经 运行 在本地使用了它 运行 heroku 上的 nodjs 服务器很好,但是当我把它放在 S3 中时bucket,在 cloudfront 后面,我点击刷新,我明白了。

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>217...1C</RequestId>
<HostId>
yu2de...dr0=
</HostId>
</Error>

有什么建议吗?

您需要配置 Cloudfront 来处理路由,以便所有路由都重定向到 index.html

查看 this 了解更多信息

如果您正在做一个简单的 HTML S3 站点以在 DEV 中进行测试并使用默认分配的域(不使用云端),请将错误页面设置为与您的起始页面相同 (index.html ).然后当页面刷新时,它重新加载相同的路由,就像一个不是SPA的传统网站。