DEV Community

Discussion on: Deploy React app to S3 & Cloudfront

Collapse
 
jh0 profile image
Jack • Edited

This is good but it doesn't cover routing to index.html for child routes of the single page web app. If you navigate directly to for example '34jg34.cloudfront.net/books' it won't resolve to index.html for the web app to resolve, it will try to find a resource called books in the S3 bucket. Anything that isn't in the bucket it should redirect to index.html. I couldn't get this to work so I've resorted to sharing the S3 bucket url itself.

Collapse
 
grendeldmk profile image
Dawid Krysiak

Hi Jack
Please find a proper solution for this:

itisoktoask.me/cloudfront-redirect...

I had the same issue (with that very page :)) - the source of the issue explained in the blogpost (tl;dr: redirect to index.html is done by default by any web server. but neither s3 or cloudfront ARE web servers :)) My solution uses official AWS solution (CloudFront function) but my post actually explains the steps :)) I committed this tutorial to the official repo, but still waiting for review (probably indefinitely, doesn't look like AWS is bothered to monitor their repos).

I hope the tutorial helps

Grendel