Lil*_*rom 2 amazon-s3 amazon-web-services angular
为了尝试在amozon虚拟主机上部署我的angular 2应用程序。索引页效果很好,但是当我尝试访问其他页面时却/users出现404 not found错误。
我尝试按照此帖子在页面刷新上使用Angular JS ui.router html5Mode(true)配置Amazon S3静态站点,但未成功。
这是我的应用程序http://ugram-team-7.s3-website-us-east-1.amazonaws.com/
感谢您的回答。
配置您的应用程序路由以使用#
const routes: Routes = [
// routes here
];
@NgModule({
imports: [
... other imports
RouterModule.forRoot(routes, { useHash: true }) // .../#/users/
],
...
})
export class SomeModule { }
Run Code Online (Sandbox Code Playgroud)
或配置S3
在您的域的S3控制台的“ 编辑重定向规则”部分中,添加以下规则:
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<HostName>domain.com</HostName>
<ReplaceKeyPrefixWith>#/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
Run Code Online (Sandbox Code Playgroud)
把它放在index.html
<script language="javascript">
if (typeof(window.history.pushState) == 'function') {
window.history.pushState(null, "Site Name", window.location.hash.substring(2));
} else {
window.location.hash = window.location.hash.substring(2);
}
</script>
Run Code Online (Sandbox Code Playgroud)