简体   繁体   English

在Amazon s3上部署的Angular 2应用程序出现404错误

[英]Angular 2 application deployed on Amazon s3 gives 404 error

I have deployed my Angular2 application on Amazon S3 successfully. 我已成功在Amazon S3上部署了我的Angular2应用程序。 It works fine. 它工作正常。 All routing works fine when I navigate using routeLinks/code. 当我使用routeLinks / code导航时,所有路由都可以正常工作。

But when I refresh the page, or jump to particular route, I get 404 error as follows. 但是当我刷新页面或跳转到特定路径时,我得到404错误,如下所示。 在此输入图像描述

The thing is, we know we have dynamic routes in Angular2. 问题是,我们知道我们在Angular2中有动态路线。 There is no physical directory with that path/route name in final code base deployed/stored in S3 bucket. 在S3存储桶中部署/存储的最终代码库中没有具有该路径/路由名称的物理目录。 But, I think S3 considers it as physical object stored in S3 bucket, which it fails to fetch. 但是,我认为S3认为它是存储在S3存储桶中的物理对象,它无法获取。

How to resolve this issue? 如何解决这个问题?

We had the same problem. 我们遇到了同样的问题。 Just go to Properties > Static website hosting. 只需转到属性>静态网站托管。

In the field Error document, add index.html, like here . 在错误文档字段中,添加index.html,就像这里一样。

If you are using AWS cli to copy dist folder to your bucket then it copies the project folder to your bucket which contains your files including index.html . 如果您使用AWS cli将dist文件夹复制到存储桶,则会将项目文件夹复制到包含您的文件(包括index.html存储桶中。

Try uploading contents of dist/< your_project>/ directly to your bucket. 尝试将dist/< your_project>/直接上传到您的存储桶。 It worked for me. 它对我有用。

I think S3 is expecting an index.html file at its root level 我认为S3期望在其根级别有一个index.html文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM