首页 > 解决方案 > 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} />

谢谢

标签: javascriptreactjsreact-native

解决方案


您需要告诉 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>

推荐阅读