javascript - React 项目构建生产在 Xampp 中不起作用
问题描述
我正在用 reactJS 开发一个项目。在这个项目中有一个登录页面,如果用户登录成功,那么他会重定向到仪表板页面。这是在本地工作,但我创建了一个构建文件夹并上传到服务器。从我尝试登录的服务器,用户登录成功,然后它重定向到仪表板页面,显示错误,称为“在此服务器上找不到请求的 URL”。谁能带我摆脱这个问题。这是代码
if (response.data['status'] === "Data not found") {
alert("Enter valid credentials")
window.location.reload();
}
else {
localStorage.setItem("login", JSON.stringify(response.data))
window.open("/Foldername/Dashboard", "_top");
}
这是路由文件夹
<Route exact path="/Foldername/Dashboard" component={Dashboard} />
谢谢
解决方案
您需要告诉 apache 为其找不到的任何文件提供索引:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
推荐阅读
- python - 从 n 开始添加列表中的每个第 n 个数字
- pyspark - Pyspark 中的地理空间分析(多边形中的点)
- java - Spark根据单元格中的值添加相同的行号
- html - Highcharts 通过按钮单击选择图表并调整宽度
- javascript - 当所有 Ajax 调用完成时调用 JavaScript 函数
- reactjs - TypeError:无法读取未定义的属性“地图”,但我的变量是空数组
- python - 打印带有表情符号的消息
- javascript - 显示对象模板角度,计算重复单词的数量
- python - Python:处理重叠数据集
- amazon-web-services - PowerShell 7 和 AWS 模块 SSM:我如何实际连接?