Skip to content

BrowserRouter is not compatible within a GitHub Pages deployment #36010

Closed Answered by ghost
JuliaMersing asked this question in Pages
Discussion options

You must be logged in to vote

///install git hubpages
$ npm install --save gh-pages

//Add some properties to the app’s package.json file. At the ***top level, add a homepage property. Define its value to be the string http://{username}.github.io/{repo-name}, where {username} is your GitHub username, and {repo-name} is the name of the GitHub repository (my-app) you created in step 3.

//expmle
"homepage": "http://.github.io/",

//in scripts
"scripts": {
//...
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
//...
"build": "react-scripts build && cp build/index.html build/404.html", // this will prevent page reloads to give a 404 error
}

// ??? if you are using the Router from react-router-dom then you need to…

Replies: 3 comments 8 replies

Comment options

You must be logged in to vote
7 replies
@derekantrican
Comment options

@mayankpruthii
Comment options

@alex-cavaliere
Comment options

@Kellen-Stuart
Comment options

@derekantrican
Comment options

Answer selected by LiteBrite82
Comment options

You must be logged in to vote
1 reply
@derekantrican
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pages Host a static website, right from your repo Product Feedback
8 participants