GitHub Pages links returning 404 #190159
Replies: 3 comments
-
|
Hey there! 👋 404 errors on GitHub Pages when navigating between links usually boil down to how GitHub's servers route and read files compared to your local development environment. Since you've already tried the conventional solutions, let's look at a few sneaky edge cases that frequently cause this:
Why it fails: The leading slash tells GitHub to look at the root domain (yourusername.github.io/about.html), completely skipping your project folder. The Fix: Remove the leading slash to make it a relative path. Change it to or .
The Fix (Option A): Switch your router to a HashRouter. This adds a # to your URLs (e.g., yoursite.com/#/about), which prevents the browser from making a new request to the GitHub server. The Fix (Option B): Add a 404.html file to your public directory with a script that redirects the request back to your index.html with the correct path parameters (often referred to as the SPA GitHub Pages hack).
The Fix: Check your repository files carefully. Ensure the exact capitalization in your href matches the actual file name character for character.
The Fix: Create a completely empty file named exactly .nojekyll in the root of your repository and commit it. This tells GitHub Pages to bypass Jekyll and publish your folders exactly as they are. If none of these hit the mark, could you share the link to your repository? Seeing the file structure usually makes the exact issue stand out immediately! |
Beta Was this translation helpful? Give feedback.
-
|
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
Beta Was this translation helpful? Give feedback.
-
|
Check how your links are formatted first. If you are using absolute paths like If you are using a single page application, I ran into this exact problem. Client side routers handle navigation in the browser, but a direct link or refresh hits the GitHub server. Since GitHub Pages only serves static files, it returns 404. You can fix it by switching to hash routing, or by adding a Are you using a client side router like React Router, or is this just plain HTML links? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Question
Body
i have a github website with two links. the site is working but when i try to press links i get 404 error. i tryed all the conventional solutions. any suggestios?
Beta Was this translation helpful? Give feedback.
All reactions