3

I'm currently working on a full-stack project mainly using ReactJS and AWS Amplify. I've successfully deployed the website but the URL routings only seem to work if I redirect from the home page. I can only load the home page www.website.com but I try to manually type in www.website.com/login/, it gives me this message

<Error>
  <Code>AccessDenied</Code>

  <Message>Access Denied</Message>

  <RequestId>B2173BDEE0658858</RequestId>

  <HostId>
  TRevHdaqGZYTUxU9W1wXc3CQccfLeznHlYLcbuF+Wr511FVmOPFBp4tpyccJ2t5QMVpvYygNNb4=
  </HostId>
</Error>

I've looked up solutions from other StackOverflow pages but it didn't seem to solve the issue.

I have tried adding a redirect rule in the AWS console provided (Getting 403 ACCESS DENIED error when deploying React Web app on AWS Amplify) but the issue persists. Is there a way to fix this?

howranwin
  • 71
  • 6
  • You have to set up a 404 (page not found) redirect on the AWS Amplify to point on the index.html. React App is SPA (Single Page App) it has its own routing, and on the AWS side, all other routes except base path will return 404, because they don't exist on the server-side, once you setup 404 to points on your React application again, React router will handle the routing. Check: https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html and pay attention to 404 redirections. – TariqN Jul 08 '21 at 15:56

1 Answers1

1

You have to set up a 404 (page not found) redirect on the AWS Amplify to point on the index.html.

React App is SPA (Single Page App) it has its own routing, and on the AWS side, all other routes except base path will return 404, because they don't exist on the server-side.

Once you setup 404 to points on your React application again, React router will handle the routing.

Check: docs.aws.amazon.com/amplify/latest/userguide/redirects.html and pay attention to 404 redirections.

enter image description here

TariqN
  • 668
  • 2
  • 9
  • 27
  • I don't have yet a better approach but the problem with this is that will cause users to get a 404 Not found when landing on domain.xyz/login which shouldn't be the case. At least, it is what I understand from the proposal and what happens to be when I try to implement it. – Alexis Duran Sep 08 '21 at 11:54
  • I solved by following https://stackoverflow.com/a/67341710/1422380 – Alexis Duran Sep 08 '21 at 12:03