[英]React App not redirecting properly on AWS Amplify
This is my first time deploying a react app on AWS Amplify.这是我第一次在 AWS Amplify 上部署 React 应用程序。 The app works fine as a SPA, the only problem is re-directions.该应用程序作为 SPA 运行良好,唯一的问题是重定向。
For example;例如; when a user completely signs up and gets a link to verify email, clicking on the link redirects me to mydomain.com/index.html.当用户完全注册并获得验证 email 的链接时,单击该链接会将我重定向到 mydomain.com/index.html。
Also when i try navigating to mydomain.com/sign-in (which should lead me to sign in page), it redirects me to mydomain.com/index.html.此外,当我尝试导航到 mydomain.com/sign-in(这应该引导我登录页面)时,它会将我重定向到 mydomain.com/index.html。
How can i resolve this?我该如何解决这个问题?
Try going to App settings->Rewrites and redirects尝试转到应用程序设置-> 重写和重定向
Add in a new rule添加新规则
</^((?.\.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>
来源应该是</^((?.\.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>
index.html
目标地址index.html
200 (Rewrite)
200 (Rewrite)
Here's an example of what the end result should look like.这是最终结果应该是什么样子的示例。
If that doesn't work, try this one如果这不起作用,试试这个
</^((?..(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>
You need to accept and route all files.您需要接受并路由所有文件。 When react builds, it runs off the index
file, but react-router manipulates the path as SPA requirements have it.当 react 构建时,它会运行index
文件,但 react-router 根据 SPA 要求操作路径。 Paste this into your rewrites and redirects.将此粘贴到您的重写和重定向中。 This will generally work if you are running a standard react router webapp.如果您正在运行标准的反应路由器 webapp,这通常会起作用。
[
{
"source": "</^((?!\\.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>",
"target": "/index.html",
"status": "200",
"condition": null
},
{
"source": "/<*>",
"target": "/",
"status": "404",
"condition": null
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.