aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
171 stars 58 forks source link

Rewrites and redirects do not work according to the documentation configuration for single pages. #1989

Closed faramir07 closed 2 weeks ago

faramir07 commented 1 month ago

Environment information

N/A

Describe the bug

I encountered an issue with the configuration of rewrites and redirects in my single-page application (SPA). Despite following the documentation, the routes are not handled correctly, leading to a 404 error when directly accessing any URL other than the root. The app is using React Router, and it should handle all routes client-side, but the server is not redirecting requests properly to the index.html file as expected.

This is how the project routes are configured image

Reproduction steps

and this is the configuration that must be done according to the documentation image.

Framework: React Router: React Router v6.22.2 Hosting: AWS Amplify Build Tool: Vite v5.0.8 Node.js Version: 20.11.1 Operating System: Windows

Jay2113 commented 3 weeks ago

Hi @faramir07 👋 , thanks for reaching out! Are you continuing to observe the 404 errors for your SPA? If yes, can you share your Amplify app id?

I put together a quick PoC with React Router v6 and wasn't able to observe this issue with the SPA rewrite rule. The app has 3 routes (/home,/about,/error) and a catch all route. You can access them directly here: https://main.db8g1w651433c.amplifyapp.com/.

faramir07 commented 3 weeks ago

My co-worker restructured the routes and the problem was solved, I can not identify where the origin of the problem arose, I guess the problem arose from our side because I have not found a similar case. We will investigate a little more in depth to find out where the error is, after a week we could fix this case as a result.

Jay2113 commented 2 weeks ago

@faramir07 I am closing this thread, as the issue has been resolved. Feel free to open a new GitHub issue if you encounter any other problems. Thanks!