Skip to content
Advertisement

Github Pages shows blank page after deployment react app

I’m tryin’ to learn reactjs and made a simple weather create-react-app project (https://github.com/zxcminusminus/react-weather/tree/master) which I’d like to deploy to Github pages using gh-pages. So my app worked perfectly on localhost but when I tryed to deploy it on gh pages I got blank page. To deploy it I added “homepage”, “deploy” and “predeploy” fields in package.json just like in tutorials, ran “npm install gh-pages” command, then ran “npm run deploy” command. I read like 10 similar questions and followed some of the tips. But nothing worked( Here is gh pages settings gh-pages

I tried adding “-d build” to deploy script like “deploy”: “gh-pages -b main -d build”

I tried replacing Route with HashRoute from this index.js App.js to this index.js App.js

I tried some little changes like changing default path in Route from “/” to this <Route path={“/react-weather”} element={}/> but still blank page(

P.S. forgive me for these links instead of embedded images, stackoverflow says i dont have 10 reputation points yet:3

Advertisement

Answer

In this file you can see that paths start with / e.g. <script defer="defer" src="/static/js/main.0065d37f.js">

Paths in gh-pages must start with ./

homepage in package.json have to be set to ./?

You will also need to use HashRouter, because gh-pages doesn’t redirect all traffic to index.html

Advertisement