有一個 React 專案使用了 BrowserHistory,放在了 Apache 伺服器上,專案首頁是localhost:8081/home。
我再進入首頁之後可以跳到其他子頁面(子路由),例如:localhost:8081/product
但是瀏覽器直接輸入localhost:8081/product是無法存取的因為Apache伺服器會解析這個路徑
我只能localhost:8081/#/product來存取。
有什麼辦法直接訪問嗎?
習慣沉默2017-06-05 11:09:46
將所有請求轉發到 index.html
配置 .htaccess 檔案:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>