react-gh-pages
react-gh-pages copied to clipboard
React website throw a 404 page not found error on reloading the page.
Whenever I reaload my react website, it throws me page not found error. What I suppose to do? But there is no issue with my other react projects that has been deployed in github.
To push new/updated code to my gthub repo, I write this code ->
- git add .
- git commit -m "change css"
- git push origin master
- npm run deploy
What is the problem?
Look at your URL, it must be github.io/{yourproject}
. Edit your packaje.json
and add homepage
(check the readme of this repository)
It looks like you are using a GitHub User Site. I had the same issue, and found it was the way I was Handling my Routing. I was using <BrowserRouter>
on my root index.js file but GitHub Pages does not support browser history like your browser does. I switched my routing to <HashRouter>
this type of router uses the hash portion of the URL to keep the UI in sync with the URL.
ReactDOM.render( <React.StrictMode> <HashRouter> <App /> </HashRouter> </React.StrictMode>, document.getElementById('root') );
Look at my PR it helped me fix this issue:
https://github.com/gitname/react-gh-pages/pull/161