存在兩個問題
一,資源文件路徑
config/paths.js
這里原來的.pathname:'/', 改成.pathname:'./'
function getServedPath(appPackageJson) { const publicUrl = getPublicUrl(appPackageJson); const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : './'); return ensureSlash(servedUrl, true); }
由此,背景圖片的地址可能是
.add-bank-sign { background: url("./../img/index.png"); //路徑前面加'./' }
二,當點擊路由跳轉的時候,會出現這樣的報錯
解決方案:
routes/index.js
把原來的
import { BrowserRouter as Router,Route, Switch, Redirect } from 'react-router-dom'
改成:
import { HashRouter as Router, Route, Switch, Redirect } from 'react-router-dom'
就可以了
當然開發的時候,最好BrowserRouter