react-gh-pages icon indicating copy to clipboard operation
react-gh-pages copied to clipboard

React website throw a 404 page not found error on reloading the page.

Open Debojyotibabai opened this issue 4 years ago • 3 comments

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 ->

  1. git add .
  2. git commit -m "change css"
  3. git push origin master
  4. npm run deploy

What is the problem?

Capture

Debojyotibabai avatar Feb 12 '21 17:02 Debojyotibabai

Look at your URL, it must be github.io/{yourproject}. Edit your packaje.json and add homepage (check the readme of this repository)

T-Damer avatar Jul 30 '21 18:07 T-Damer

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') );

israelmrios avatar May 04 '22 06:05 israelmrios

Look at my PR it helped me fix this issue:

https://github.com/gitname/react-gh-pages/pull/161

b-smiley avatar Aug 30 '23 16:08 b-smiley