Skip to content

Commit e8b5b19

Browse files
committed
Document what npm build does and pushState
1 parent 6bda4b9 commit e8b5b19

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/react-scripts/template/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,20 @@ This feature is experimental and still [has major usage issues](https://github.c
863863
864864
## Deployment
865865
866-
## Building for Relative Paths
866+
`npm run build` creates a `build` directory with a production build of your app. Set up your favourite http server so that a visitor to your site is served `index.html`, and requests to static paths like `/static/js/main.<hash>.js` is served with the contents of the `/static/js/main.<hash>.js` file.
867+
868+
```sh
869+
cd ./build
870+
python3 -m http.server 80
871+
```
872+
873+
### `pushState` routers
874+
875+
If you use routers that use the HTML5 `pushState` history API under the hood (for example, React Router using `browserHistory`), many static file servers will fail. For example, if you used react-router with a route for `/todos/42`, the development server will respond to `localhost:3000/todos/42` properly, but the python3 http.server serving a production build as above will not.
876+
877+
This is because when there is a fresh page load for a `0.0.0.0/todos/42`, the server looks for the file `build/todos/42` and does not find it. The server needs to be configured to respond to a request to `/todos/42` by serving `index.html`.
878+
879+
### Building for Relative Paths
867880
868881
By default, Create React App produces a build assuming your app is hosted at the server root.<br>
869882
To override this, specify the `homepage` in your `package.json`, for example:

0 commit comments

Comments
 (0)