reactjs - Simplest way to put everything under http://localhost:3000/app instead of http://localhost:3000/ in React
问题描述
How to change root path of React app, to be specific: all html, css and js will be under http://localhost:3000/app instead of just http://localhost:3000?
Is there a simple way to amend existing app to just have one more level?
(this is useful when having reverse proxy e.g. nginx or apache in front of the React)
Note that compiled project should also have the same /app prefix everywhere
Many thanks
解决方案
Found solution for compiled code!
Add to package.json
"homepage": "/app/",
Add to index.html
<head>
<base href="%PUBLIC_URL%/">
</head>
Now build the app with npm run build
Copy files to web server (e.g. Nginx) cp -r build /usr/share/nginx/html/app
Access this at:
http://localhost/app
So all paths should have prefix app/
now
推荐阅读
- spring-boot - 更正应用程序的类路径,使其包含一个兼容的 io.jsonwebtoken.SignatureAlgorithm 版本
- python - 决策树回归器的结果如何连续?
- android - Android Room fallbackToDestructiveMigration 通过保留用户数据
- c# - 当值是列表时,插入键值对的第一个值
- sql - 如何在 PostgreSQL 中转移整个组?
- java - mvnDebug模式未开启调试模式
- javascript - Livecycle Designer:JavaScript - 从根中按名称和位置查找元素
- security - Kubernetes / Openshift 服务内通信
- python - 在 Python 中为 C++ 代码制作词法分析器时遇到问题
- ios - 我无法从 widgetKit 扩展上的应用程序中检索 xcdatamodeld 数据