Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@barhoring
Created June 8, 2021 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barhoring/34af868162d366a6a89641c0242d6807 to your computer and use it in GitHub Desktop.
Save barhoring/34af868162d366a6a89641c0242d6807 to your computer and use it in GitHub Desktop.
How to deploy a routed React app to gh-pages

How to deploy a routed React app to gh-pages

Add homepage to package.json "homepage": "https://{user_name}.github.io/{repo_name}/",

Install gh-pages package

npm i gh-pages

Replace all '/' in the app with process.env.PUBLIC_URL example, from: <Link to='/'>Home</Link> to <Link to={process.env.PUBLIC_URL}>Home</Link>

Add these under scripts in package.json "predeploy": "npm run build", "deploy": "gh-pages -d build"

Run npm run deploy and your site should be on https://{user_name}.github.io/{repo_name}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment