-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Amplify Console 200 (Rewrite) fails on SPA React (Router) Application #2498
Comments
In case it helps to debug.. After having this fail in Chrome per the above description, I then tried in MS Edge. That worked perfectly for a few minutes, afterwards it failed in a similar fashion. Changing the type to 404 makes the website work again (although a Ctrl-R refresh always pushed it back to the root), but then afterwards switching it again back to 200 does not work, not even for a minute. I tried clearing my cache in chrome in case that might have been an issue - no luck. |
I have a similar issue. |
This is because your assets are not loading properly. We launched a feature to support regex based on this thread here: https://forums.aws.amazon.com/thread.jspa?threadID=294311&tstart=0 Try using regex in source. The format is </.../>. |
Even with the following rule: I still get the same error. This project works just fine when using |
I have the same issue. Works perfectly on S3 with success:index.html and error:index.html - but I don't get the redirects to working state in amplify console |
@elsenhuc The one I posted above: As that one worked for me. I'd suggest you give that a go. I don't know regular expressions well enough to really know what the difference is between those two, so I can't help beyond that. I'll close this thread now as my issue is solved, but if that doesn't work for you please feel free to reopen. |
Hi, I went through that regex as well. |
@elsenhuc |
hmmm..strange - In fact I am using react and ReactRouter already... |
I'd do it differently, namely: That format of URL parameters is working for me with amplify console. |
That is something different...you are using a path (I do that already). this piece works: |
Can you change it so that URL should be /events/1234/1/2 and have the Route component look like: You may need some logic to make sure it doesn't show all 3 instances of the |
well..while this might be possible it's still...sort of a lame workaround :-) |
This worked for me source: target address: type: |
@elsenhuc Did you ever get this issue resolve for ?querystrings. I too having trouble routing with querystring paramters. Getting stripped out. If I deploy using |
The docs have been updated: https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html but in the meantime I had changed my code and used a URL redirect inside react, rather than a querystring parameter - so I "avoided" it |
This worked for me too source: target address: type: |
I have a SPA Create react app and am trying to get these redirects figured out...
|
Ahh my bad. I needed my target to be "/" rather than "index.html". The following did the trick!
|
I had the same problem and was able to solve it by adding the suggested redirects. The images and routes work correctly, however, the custom fonts are not loading. When I leave the default redirects from the deployment, the correct fonts are shown but, when changing the source to </^((?!.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/> they stop loading. Any Ideas? |
It's not an amplify's issue. |
@chrisfowler did you ever figure out how to keep the parameters with react and amplify? |
The parameters that worked immediately for me were: Without this rule the app was behaving incorrectly on the re-routing actions. Regards, |
The rewrite is working for me at the first level (e.g. /login) but not if I have a second level of routing (e.g. /auth/login) Two issues I've been struggling with:
Has anyone else got amplify console working with this kind of app routing? |
I got somewhere with my angular app (with routing) hosted in a subdirectory (quite similar to what react would be). Solved with this:
|
It's worth using the regular expression in the docs: https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html It includes "map", which will make sure your source maps are loading if needed. |
Thanks! this worked for me! |
Hi, how can I change Rewrites and Redirects in amplify console? |
@tomyitav I used the above rule that @DiegoArrieta shared on 2/22 on a react app that I just created today with I added xml to the pattern to support serving public sitemap.xml files. Here's the snippet I used:
Good luck! |
I added </^((?!.(xml|css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/> with a target of / and a rule of Rewrite 200. This solution works for me for URLs that have one element after /, but anything beyond that still has the issue of resulting in a blank page. For example: I'm able to refresh the page while at example.com/account If, however, I try to refresh the page while on example.com/account/edit I get a blank page again. Has anyone figured out how to deal with this? |
@elsenhuc: did you found a solution for the parameter problem? |
Hi guys I realized this fix works except when one of the queries has the key called |
I have the same problem and I did not find a solution. I tried thousands of regex strings but no solution so far. I am super frustrated now. Working for houres on this problem now. edit: @Caoimhin89 in case you did not find a solution or it helps anyone. Seems like I have a dirty fix at least for my react app: [ With this at least /result/1234 routes work in react |
Hello , I have the same error here but with a flutter web application. I have tried most of the proposed solutions but nothing works. |
Also in the react router. I can only use one level of routing i.e. /Abc /bcd and not /abc/bcd. Why is the case? Is there a better alternative to React routing when using Amplify? |
I got a stupid fix for sub-routes/nested routes not working in amplify. Problem: /GDPClock works fine. /GDPClock/USA loads a blank white page. The reason is that Amplify loads static resources from /GDPClock/static/js/abc.js but it should be /static/js/abc.js Hack: I do not understand why does Amplify make it so complicated to just use some basic routing. |
Hey I had a similar issue with my React/react-router-dom SPA deployment. I encountered an issue where I could only access the home page directly. For example, visiting domain.com would load the page, and I could navigate to the /about section by clicking links. However, if I refreshed the page or, typed domain.com/about directly into the browser it would result in a 404 error. Although I added the correct rewrite rule, it still did not resolve the problem. The solution that ultimately worked was adjusting the permissions of the S3 buckets related to my deployment. Specifically, I had to turn off the "Block all public access" setting. Once I made this change, the 404 issue was resolved, and I could access all pages directly. |
were you able to solve it? |
Thanks god !!!! source: target address: type: |
Describe the bug
When using the Amplify Console to build a project, the react router performs as expected when I click new links. When I hit Ctrl-R for refresh, it pushes me back to:
https://..amplifyapp.com/index.html
The default "rewrites and redirects" is:
Source address: /<*>
Target address: /index.html
Type: 404 (Not found)
So that makes sense.
When I change the rewrite to INSTEAD be:
Source address: /<*>
Target address: /
Type: 200 (rewrite)
Things seem to work as expected initially. The page refreshes to a non-root page (e.g., if I'm at /user/account, a Ctrl-R will keep me there), but for some reason reason after a few minutes, I get an error in the console and the page is blank. I can change it back to a 404 (Not found) type of redirect, but that doesn't get me the desired behavior.
Note, the app works just fine with a local npm start command, as well as when using the CLI with "amplify publish", both on an S3 domain as well as a custom domain (via Route 53). I am not using a custom domain with the amplify console (yet) as I wanted to give it a shot to maybe help me with "dev-test-production" workflows.
Screenshots
Desktop (please complete the following information):
Thank you!
The text was updated successfully, but these errors were encountered: