【发布时间】:2022-08-24 19:10:30
【问题描述】:
我试图将访问我的应用程序的某些页面仅限于经过身份验证的用户。然而,如果匿名用户第一次点击页面,它会加载并且刷新后用户会收到 401 错误。
这是我的反应路由器
<Switch>
<Route path=\'/\' exact component={Dashboard} />
<Route path=\'/records\' component={Records} />
<Route path=\'/livecam\' component={LiveCamera} />
<Route path=\'/debug\' component={Debug} />
<Route path=\'/settings\' component={Settings} />
</Switch>
我的 Azure 静态 Web 应用程序路由:
{
\"routes\": [
{
\"route\": \"/records*\",
\"allowedRoles\": [\"authenticated\"]
},
{
\"route\": \"/livecam*\",
\"allowedRoles\": [\"authenticated\"]
},
{
\"route\": \"/settings\",
\"allowedRoles\": [\"admin\"]
}
],
\"navigationFallback\": {
\"rewrite\": \"/index.html\",
\"exclude\": [\"/assets/*.{png,jpg,jpeg,gif,bmp}\", \"/static/css/*\"]
},
\"mimeTypes\": {
\".json\": \"text/json\"
},
\"responseOverrides\": {
\"400\": {
\"rewrite\": \"/invalid-invitation-error.html\"
}
}
}
谢谢!
-
您能否准确说明“匿名用户第一次加载页面时单击页面”是什么?就像他们从
\"/\"开始并单击链接以导航到特定页面?然后页面重新加载后有 401 响应? -
用户从路由 \"/\" 开始。单击 \"/records\" - 它可以工作 刷新页面 \"/records\" 它失败并显示 401 我的期望是,一旦用户单击指向 /records 的链接,它将立即失败。正如我所理解的问题是路由发生在客户端而不是服务器端,这就是为什么第一次尝试现在按预期工作的原因。
-
CRA deployments Azure 文档中的任何内容对您有帮助吗?
-
抱歉不行。
标签: react-router azure-static-web-app azure-static-web-app-routing