Removing the repeated github username from the homepage url fixed the problem:
Correct value for "homepage":
"homepage": "https://myusername.github.io/myreponame"
You need to add your root path to the basename prop of BrowserRouter
If you are not using BrowserRouter, add the following
import BrowserRouter from 'react-router-dom/BrowserRouter'
ReactDOM.render((
<BrowserRouter basename={process.env.PUBLIC_URL}>
<App />
</BrowserRouter>
), ...)
process.env.PUBLIC_URL is is a part of the node.js library and is a dynamically generated url that changes based on what development mode you are in, whether you are working on your app locally, or on an actual production server like GitHub pages (https://parthaaaaa.github.io/firstwebapp/).
Also update the route to your home/firstwebapp component(if any)
<Route exact path='/firstwebapp' render= ... />} />
to
<Route exact path='/' render= ... />} />
With this change when the route path matches the ‘process.env.PUBLIC_URL’ (reponame + ‘/’) it will render your firstwebapp component
In your package.json homepage is not correct, so it is messing up the build.
Change
"homepage": "https:Parthaaaaa.github.io/firstwebapp",
to
"homepage": "https://parthaaaaa.github.io/firstwebapp",
Then try building and deploying again.
Documentation on Building for Relative Paths
Code is deployed, but page is blank
Blank page when deploying react site to github pages with custom domain name
Blank Page after deployment
Blank Screen When Deploying React Site to Github Pages- No Error in Console
Videos
I am trying to deploy my React app using Github pages using a custom domain that I own but I am unable to deploy it. I am stuck on what the issue is. I noticed that when I reload the page I am getting a repeat in my domain as an error, but unsure if this is the problem. My public website repository is available here https://github.com/ryanl35/react-website-ryan-1. Help is greatly appreciated. Thank you!
When loading the site After reloadingVery frustrated, as this should be a simple task. Been at it for multiple days now and i feel very stupid. I followed just about every tutorial on the internet, but i feel like this is some sick joke. I am trying to deploy a functional website on github pages to work on a portfolio using react, but the page is blank. Every other tutorial out there seems to work just fine so i am missing something that everyone is leaving out of documentation.
here is where i am trying to launch my site https://akellergit.github.io/portfolio/, however as you can see, the readme.md is being shown instead of index.html....
so i tried https://akellergit.github.io/portfolio/public/index.html and the page is just straight up blank. the page is officially published and everything so there is no issue there.
Here is what the landing page looks like when running from lap top (at localhost:3000 ).
https://raw.githubusercontent.com/grommet/grommet-starter-new-app/master/public/cra-landing-page.png
Please, mighty ReactJS Gods, what am I doing wrong?
EDIT: here is the source for this super simple stuff https://github.com/AKellerGit/AKellerGit.github.io/tree/master/portfolio
I believe u need to npm build or sth along those lines and then upload it to a site. Just basing it off the screenshot.
Try https://www.netlify.com You just need to link it to your GitHub repo (or other) and it will auto detect your React app just click next and setup url, dns etc and you're done !
Never use BrowserRouter on GitHub Pages. There are some issues with it, it always shows blank screen. Use HashRouter instead, that will most probably work.
import { HashRouter } from "react-router-dom";
// some code here
return (
<HashRouter base="/">
<App />
</HashRouter>
)
The create react app documentation says that:
GitHub Pages doesn’t support routers that use the HTML5
pushStatehistory API under the hood (for example, React Router usingbrowserHistory). This is because when there is a fresh page load for a url like http://user.github.io/todomvc/todos/42, where/todos/42is a frontend route, the GitHub Pages server returns 404 because it knows nothing of/todos/42. If you want to add a router to a project hosted on GitHub Pages, here are a couple of solutions:
- You could switch from using HTML5 history API to routing with hashes. If you use React Router, you can switch to
hashHistoryfor this effect, but the URL will be longer and more verbose (for example, http://user.github.io/todomvc/#/todos/42?_k=yknaj). Read more about different history implementations in React Router.
Therefore you should use hashHistory if you want to host your site on GitHub Pages.
Here is the link to documentation.
If you don't wish to change router, try deploying it on Netlify which is also another free hosting provider. But again for Netlify deployment, follow the documentation, which says:
To support pushState, make sure to create a public/_redirects file with the following rewrite rules:
/* /index.html 200
I see that you have managed to deploy your React project to Github pages successfully, but here is how I did it in case anyone needs help:
- First things first, make sure that your ".git" folder and your project are in the same folder.

- Run
npm run build. You should have adistfolder now. - Open the file
vite.config.js(or.ts). - Add the
basefile with your repository name. Include the two/.
Example: let's say your github project's URL is https://github.com/atlassian/react-beautiful-dnd.
export default defineConfig({
base: "/react-beautiful-dnd/",
plugins: [react()],
});
- Open your
.gitignorefile and delete thedistline from it. You want to make sure that thedistfolder is pushed to github. git add .git commit -m "deploy"git subtree push --prefix dist origin gh-pages- Wait for a couple minutes (in my case it took 4 minutes) and open the page. In the example above, the URL would look like this: https://atlassian.github.io/react-beautiful-dnd
In case it's still showing a blank page, it's very likely to do with the step number 3. Ensure you added the correct repository URL and that it begins and ends with the / sign.
That is about it, I hope it helps. I used this blog post for guidance, it is a more detailed explanation of the above.
Ok, so to solve this the only thing that I had to do was to add base:"{repName}" to the vite.config.ts file.
Source: https://vitejs.dev/guide/static-deploy.html
The images were not loading, I used this to fix them: Github pages vite JS build not showing the images