reactjs - 使用 AWS Amplify 托管保留查询字符串 - React
问题描述
我目前有一个在本地工作的反应应用程序react-router-dom
,但在使用AWS Amplify部署时不能。
问题是,当我路由到 URL 并使用查询字符串时,浏览器会获得重定向并删除查询字符串。
例如,当我路由到 时/path?value1=foo&value2=bar
,浏览器得到 301 并重定向到 url:/0000000X/path/
如下所示
我尝试过使用哈希值以及本文中提到的方法/path/?value1=foo&value2=bar
,但没有成功。
下面是我的实现:
按钮.js
href: '/path?value1=foo&value2=bar'
路径.js
import queryString from 'query-string'
const values = queryString.parse(this.props.location.search)
console.log(values.value1)
console.log(values.value2)
路由.js
<AuthenticatedRoute path="/path" exact component={Path} props={childProps} />
所有这些在本地都可以正常工作,重定向,我可以访问查询字符串参数,但不能在 S3 中。提前致谢!
解决方案
将此添加到 AWS Amplify 的重写和重定向:
[
{
"source": "</^((?!\\.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>",
"target": "/index.html",
"status": "200",
"condition": null
},
{
"source": "/<*>",
"target": "/",
"status": "404",
"condition": null
}
]