存在两个问题
一,资源文件路径
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