Plesk 显示 404 页面未找到 Reactjs

问题描述

我正在尝试将我的应用程序上传到 Plesk 并且它工作正常,除非我尝试呈现非 .HTML 页面组件,例如它通过错误 404 页面未找到我理解这与服务器有关,但我不知道如何修复它。 我在 Vercel 上上传了相同的应用程序,它在所有页面和组件上都运行良好。

<Route exact path="/" render={() => {window.location.href="Home.html"}} />
<Route path="/quiz" component={App} />
<Route path="/questions" render={() => {window.location.href="questions.html"}} />
<Route path="/profile" render={() => {window.location.href="profile.html"}} />
<Route path="/about" render={() => {window.location.href="about.html"}} />

正如你所看到的,我的大部分路由都是到 .HTML 页面,当我访问域/测验时,它们都在工作,我发现 404 页面未找到。

如果有解决方法,我将不胜感激。

而且我已经尝试按照许多以前的解决方案中的建议创建 .htaccess,但它没有解决问题。

解决方法

https://stackoverflow.com/a/60342849/7345217 建议的解决方案有效

在 React App 的 Public 文件夹中创建一个 .htaccess 文件。

将这些行放在文件中

<IfModule mod_rewrite.c>
   Options -MultiViews
   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^ index.html [QSA,L]
</IfModule>

保存并(npm react 或 yarn build),它应该可以工作