Deployment of React App on Github Pages with React Router
On Hithub We can publish our app for free! How to do this:
- install github pages in our project:
“npm install –save gh-pages”
- add property homepage to package.json (get homepage from Your Github repo - has to be public, url will be in settings) f.e:\
” “homepage”: “https://yorghname.github.io/reponame/” “
-
add scripts in srcipts section : “predeploy” and “deploy” in package.json
“predeploy” : “npm run build”, “deploy: “gh-pages -d build”,
-
use command “npm run deploy” to publish Your app!
Notes:
- if app use router, We have to add basename path, so routes will be working correctly. To do this add:
“<Router basename={process.env.PUBLIC_URL}>”
That’s all!