搜尋

首頁  >  問答  >  主體

php - React-Router 的 BrowserHistory,無法直接存取

有一個 React 專案使用了 BrowserHistory,放在了 Apache 伺服器上,專案首頁是localhost:8081/home。

我再進入首頁之後可以跳到其他子頁面(子路由),例如:localhost:8081/product

但是瀏覽器直接輸入localhost:8081/product是無法存取的因為Apache伺服器會解析這個路徑

我只能localhost:8081/#/product來存取。

有什麼辦法直接訪問嗎?

大家讲道理大家讲道理2820 天前816

全部回覆(1)我來回復

  • 習慣沉默

    習慣沉默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>

    回覆
    0
  • 取消回覆