这是一个简单的问题,但我是开发人员,但我对虚拟主机一无所知,我在 ReactJS 中有一个应用程序,它在主页 www.example.com 中运行良好,但是当我转到 www.example.com/不知怎么的,这让我返回了 404。我的虚拟主机配置文件:
<VirtualHost *:80>
ServerName somepage.com
ServerAlias somepage.com www.somepage.com
DocumentRoot "/var/www/somepage/build/"
DirectoryIndex index.html
<Directory "/var/www/somepage/build/">
AllowOverride All
Order allow,deny
Allow from All
</Directory>
ErrorLog /var/log/apache2/somepage_error.log
CustomLog /var/log/apache2/somepage_access.log combined
</VirtualHost>
谢谢你的帮助。
最佳答案
实际上,在 react 中,每条路线,例如 example.com/something
或 example.com/something/inside_something
都应该使用根文件夹中存在的 index.html 进行响应,而不管被击中的路线。在 apache Web 服务器中,默认情况下/something 意味着打开根文件夹中的 something
文件夹并从那里呈现 index.html
尝试此解决方案(如果有效)https://gkedge.gitbooks.io/react-router-in-the-real/content/apache.html
关于reactjs - React JS 虚拟主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45742925/