Reputation: 13397
I have Angular app that uses routing, built and deployed to an S3 bucket. It works fine if I go to the root of URL of the app. e.g. www.my-app.com.s3.foo.bar.amazonaws.com/
And it works fine within the app. For example if I follow a router link that points to ['/home'] it goes to www.my-app.com.s3.foo.bar.amazonaws.com/home
and so on.
But if I go directly to, say, www.my-app.com.s3.foo.bar.amazonaws.com/home
, I get an S3 error saying the resource does not exist. This is true - there is no file in the S3 bucket corresponding to /home.
How do I ensure that URL requests get routed through the app rather than to S3?
Update: It looks like CloudFront might do this. What do I configure in CloudFront?
Upvotes: 5
Views: 1622
Reputation: 1863
You can configure CloudFront to handle what is a "not found" page from the S3 perspective, by returning the appropriate root page of your SPA.
Upvotes: 4