I currently have a react app using react-router-dom
that works locally but not when deployed using AWS Amplify.
The problem is that when I route to a URL and use query strings, the browser gets a redirect and drops the query strings.
For example when I route to /path?value1=foo&value2=bar
, the browser gets a 301 and redirects to url: /0000000X/path/
as shown below
I have tried using hash values as well as the /path/?value1=foo&value2=bar
approach as mentioned in this post with no luck.
Below is my implementation:
Button.js
href: '/path?value1=foo&value2=bar'
Path.js
import queryString from 'query-string'
const values = queryString.parse(this.props.location.search)
console.log(values.value1)
console.log(values.value2)
Routes.js
<AuthenticatedRoute path="/path" exact component={Path} props={childProps} />
All of this works fine locally, redirects and I can access the query string params, but not in S3. Thanks in advance!
Add this to AWS Amplify's Rewrites and Redirect:
[
{
"source": "</^((?!\\.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>",
"target": "/index.html",
"status": "200",
"condition": null
},
{
"source": "/<*>",
"target": "/",
"status": "404",
"condition": null
}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With