方法一
function getServedPath(appPackageJson) {
const publicUrl = getPublicUrl(appPackageJson);
const servedUrl =
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : './');
return ensureSlash(servedUrl, true);
}
修改config/paths.js中37行,即可
yarn build
打包后,直接路径nginx挂载路径直接到build下,http://localhost:9001即可成功访问
server {
listen 9001;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root D:\workspace\citysimulate\build;
autoindex on;
}
}
方法二
访问路径需要带上项目名称,如http://locahost:9001/citySimulate
同样需要修改修改config/paths.js中37行,如上面图中所示
然后:
<Provider store={store}>
<HashRouter basename="citySimulate">
...
</HashRouter>
</Provider>
HashRouter
中添加basename
属性