简体   繁体   中英

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(

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

In this file you can see that paths start with / eg <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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM