![](/img/trans.png)
[英]React-Redux application on sub-directory using Apache Server
[英]React Router not functional when deployed in a sub-directory On Apache
我在將我的 React 應用程序部署到 appache 上的子目錄時遇到了很大的問題。 我正在使用 create-react-app 和 React router v4。 當我訪問網址 www.example.com/myApp 時。 當我的主頁正確呈現時,我正在呈現的 html。
但是,如果我嘗試通過在地址欄中手動鍵入路線來訪問注冊頁面,則會收到 404 Not found 錯誤。
我做了什么。
請我一直在這幾天試圖找出我做錯了什么,但我似乎無法弄清楚。
Apache 嘗試為請求的路由查找資源。 您需要將所有請求重定向到您的索引,以便可以加載反應包並且反應路由器可以完成它的工作
這已經解決了幾次,所以我會參考其他有用的答案
通過添加以下 Rewrite* 行來更改 VirtualHost 配置(通常在 /etc/httpd/conf.d\\vhosts.conf 中找到):
<VirtualHost *:8080>
ServerName example.com
DocumentRoot /var/www/httpd/example.com
<Directory "/var/www/httpd/example.com">
...
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
</VirtualHost>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.