【问题标题】:React project build production is not working in XamppReact 项目构建生产在 Xampp 中不起作用
【发布时间】:2020-01-24 10:29:17
【问题描述】:

我正在用 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} />

谢谢

【问题讨论】:

    标签: javascript reactjs react-native


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      • 2018-10-15
      • 2018-01-18
      • 2018-07-23
      • 2020-06-22
      • 2020-09-24
      • 2021-03-13
      相关资源
      最近更新 更多