我刚刚使用 create-react-app 创建了一个 React 应用程序,该应用程序从端口 3000 启动,很好。我想使用前缀访问应用程序,在我的例子中是 /node 和端口 80,即http://localhost/节点 http://localhost/node。为此,我配置了 apache:
<Location /node>
Allow from all
ProxyPass http://localhost:3000/ retry=0
ProxyPassReverse http://localhost:3000/
</Location>
并且部分工作,我可以访问http://localhost/节点 http://localhost/node,但页面无法正确加载,因为捆绑包的路由是静态的。使用控制台我看到了请求http://localhost/static/js/bundle.js http://localhost/static/js/bundle.js失败并未找到。
bundle.js 不在index.html 中,因此应该由webpack 注入。
我一直在寻找配置 webpack 的位置来更改配置,将 bundle.js 放在 node/static/js/bundle.js 或类似的东西下。
如何不使用apache代理。
编辑“package.json”,添加
"homepage": "http://localhost/" ,
Not "homepage": "http://localhost/node"
Result:
$ head package.json
{
"name": "reactapp",
"private": true,
"homepage": "http://localhost/",
"devDependencies": {
....
Run
npm run build
创建符号链接
ln -s create-react-app/build /var/www/html/node
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)