Closed tristenwallace closed 5 months ago
When you refresh a page, the browser tries to directly access the file on the server, which doesn't exist for dynamic routes in an SPA. Instead, all routes should return the index.html file, which then lets the client-side routing handle the correct view.
Navigate to the Behaviors tab.
Select the behavior for your default cache behavior (usually /).
Click Edit.
Ensure the following settings:
Create a custom error response:
S3 Configuration: Ensure static website hosting is enabled and both index and error documents are set to index.html.
CloudFront Configuration:
Invalidate Cache: Ensure CloudFront serves the latest content.
Problem Summary
Our Single-Page Application (SPA), hosted on Amazon S3, encounters issues where interactions that result in navigation to paths like
/login
lead to a 404 error upon page refresh or when entering incorrect login details. This issue stems from the S3 bucket's inability to handle routes that do not correspond to physical files appropriately. Currently, as a workaround, all such errors redirect users back to the home page.Details
Amazon S3, which hosts our static SPA, looks for a file matching the exact path in the URL when a page is refreshed or navigated to directly. Since SPAs typically manage routing on the client side and utilize a single
index.html
to handle all routes, this direct path lookup fails for paths like/login
, resulting in a 404 error.Current Workaround
As a temporary measure, any 404 error redirects to the home page (
index.html
). This is not an ideal solution as it disrupts the user experience, especially during interactions requiring feedback like login attempts.Expected Behavior
The application should maintain the current route or display appropriate feedback without redirecting to the home page in cases of:
Steps to Reproduce
<application_url>/login
<application_url>/dashboard
Possible Solutions
index.html
for all unmatched routes with a 200 status, allowing client-side routing to function correctly.