How should I configure create-react-app to serve app from subdirectory?

前端 未结 6 1156
死守一世寂寞
死守一世寂寞 2020-12-08 02:59

I have classic web application rendered on server. I want to create admin panel as single page application in React. I want to server admin panel from https://smyapp.example

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 03:17

    You should add entry in package.json for this.

    Add a key "homepage": "your-subfolder/" in your package.json All static files will be loaded from "your-subfolder"

    If there is no subfolder and you need to load from same folder you need to add the path as "./" or remove the entire line which has "homepage": "xxxxxxxxxx"

    "homepage": "./"

    From the official docs

    By default, Create React App produces a build assuming your app is hosted at the server root. To override this, specify the homepage in your package.json, for example:

    "homepage": "http://mywebsite.com/relativepath",

    Note: If you are using react-router@^4, you can root s using the basename prop on any .

    From here and also check the official CRA docs

提交回复
热议问题