我将Vite React.js应用程序上传到服务器。我正在使用 nginx 服务器。应用程序运行良好。但是当我转到另一个页面并刷新时,该网站无法正常工作。它显示 404 未找到错误。我在nginx中添加了以下配置,问题仍然存在
location / {
try_files $uri $uri/ /index.html;
}
应用程序被配置为子目录,如 www.domain.com/stock/app 当我刷新到给定的网址时,它工作正常,但是当我切换到其他路由(如 www.domain.com/stock)时/app/login 或 www.domain.com/stock/app/dashboard 并刷新显示的页面 404 Not Found。
我该如何解决这个问题?
放入文件夹public:.htaccess
在 .htaccess 中:
<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>