4 回答

TA貢獻1829條經驗 獲得超7個贊
為了讓它工作,我做了以下步驟:
添加.htaccess文件到public文件夾:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
修改package.json并添加:
"homepage": "http://my-url.com/foldername"
在App.js將文件夾名稱添加到<Route path="<<here>>" />:
<Route path="/foldername/" exact component={Home} />
<Route path="/foldername/contact" exact component={Contact} />

TA貢獻1798條經驗 獲得超3個贊
我在以前的項目中遇到過這個問題,因為它是帶有 apache 的 GoDaddy Linux 主機,所以我添加了這一行
"homepage": "my-url.com" 到你的 package.json
然后我編輯了我的 .htaccess 文件,在上面添加了我的主要路線
我使用的文件有這個內容
RewriteOptions inherit
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . / [L]

TA貢獻1877條經驗 獲得超1個贊
我認為這可能與 react-router 處理客戶端或服務器端渲染 (SSR) 渲染的方式有關。請檢查此文檔片段以正確設置客戶端 https://create-react-app.dev/docs/deployment/#serving-apps-with-client-side-routing
或者嘗試將渲染配置更改為 SSR,應該沒問題。

TA貢獻1780條經驗 獲得超5個贊
有同樣的問題!我解決了它以BrowserRouter
在HashRouter
我的App.jsx
. 我的 FTP 無法處理BrowserRouter
.
在我更新所有內容后,它工作正常。
添加回答
舉報