[英]404 Page not found on page refresh
我有一个基本的 create-react-app 配置,它部署在 Azure devops 上。 我的后端也部署在python的Azure Devops上。
所有服务和 UI 都部署在 Kube.netes 集群上。
该网站在 BASE_URL 上运行良好,它指向 index.html 并加载页面路由回它或刷新它。
我能够在应用程序的流程中前进。
例如:BASE_URL --> BASE_URL/about (工作正常)
BASE_URL/关于
404 | The requested path could not be found
) 我正在使用{ BrowserRouter, Route } from "react-router-dom"
根据我的阅读和理解,服务器不理解它,因为 URL 在本地更改并且客户端处理它,当我们单击一个链接时,一些 Javascript 运行它操纵地址栏中的 URL,而不会导致页面刷新,反过来导致 React Router 在客户端执行页面转换。
我尝试过的事情:
<?xml version="1.0"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="React Routes" stopProcessing="true"> <match url=".*" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" /> </conditions> <action type="Rewrite" url="/" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
{ "navigationFallback": { "rewrite": "/index.html", "exclude": ["/images/*.{png,jpg,gif}", "/css/*"] } }
<base href="/">
(问题未解决,在stackoverflow答案中遇到)谁能指导我缺少什么,或者需要在 index.html 或 devops 中完成任何外部配置?
提前致谢。
我遇到了这个问题 - 我的 routes.json 文件在根目录中
我将 routes.json 添加到公用文件夹并且它有效。
{
"routes": [
{
"route": "/*",
"serve": "/index.html",
"statusCode": 200
}
],
"navigationFallback": {
"rewrite": "index.html",
"exclude": ["/images/*.{png,jpg,gif}", "/css/*"]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.