获得“拒绝访问"在 AWS Amplify 上重新加载 React 应用程序时出错 [英] Getting an "Access Denied" error when I reload my React app on AWS Amplify

查看:22
本文介绍了获得“拒绝访问"在 AWS Amplify 上重新加载 React 应用程序时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在 AWS Amplify 上运行的 React 应用程序.我的 React 应用程序使用 react-router-dom 库来路由到不同的组件.在 CLI 中运行 amplify publish 后,在应用程序的根目录 (obktraining.com) 浏览器中一切正常,我也可以路由到应用程序中的其他组件也很好.但是,当我在路线上刷新浏览器 (obktraining.com/menu) 时,我收到一条拒绝访问的错误消息.

I am working on a React app that's running on AWS Amplify. My React app is using the react-router-dom library to route to different components. After running amplify publish in the CLI, at the root of the app (obktraining.com) everything is fine in the browser, I can also route to other components in the app just fine as well. But when I refresh my browser while I am on a route (obktraining.com/menu), I get an Access Denied error message.

我在 Amplify 中发现了有关重写和重定向类似问题的其他帖子,但给出的解决方案对我不起作用.

I have found other posts about similar issues regarding rewrites and redirects in Amplify, but the solutions given do not work for me.

这是错误的图像:

我的 Amplify 应用程序重写 &重定向:

My Amplify app rewrites & redirects :

同样,错误仅在我刷新路线(obktraining.com/menu 或 obktraining.com/drinks)而不是 obktraining.com 时显示.问题是由 react-router-dom 库引起的还是 Amplify 设置的问题?我不知道从哪里开始.

Again, the error only displays when I refresh on a route (obktraining.com/menu or obktraining.com/drinks) not on obktraining.com. Is the issue being caused by the react-router-dom library or is it an issue with Amplify settings? I am not sure where to go from here.

推荐答案

几天以来我一直面临同样的错误.错误是由放大设置引起的.解决方法很简单,通过添加新规则来编辑您的重写和重定向.

I have been facing the same error since days.The error is being caused by the amplify settings. The solution is simple, Edit your Rewrites and redirects by adding a new rule.

源地址 = </^[^.]+$|.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>

目标地址 =/index.html

状态 = 200(重写)

国家代码可以留空

保存并再次尝试刷新您的应用.它应该可以工作.

Save and try refreshing your app again. It should probably work.

使用此作为参考:https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa

这篇关于获得“拒绝访问"在 AWS Amplify 上重新加载 React 应用程序时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆