I've created a React webpage based on this template. I've tried to deploy this website on GitHub pages as described here, and it does render partially - see here, there are two main issues:
- Only parts of the website render successfully. It seems the ElasticUI components are not properly rendering and
- when I try to navigate to any of the other tabs on the website (e.g. "Speakers"), a 404 error is given.
Running this website on localhost works perfectly, so it seems to be an issue with the deployment on GH Pages. The code can be found here: .
I've also tried to deploy this website on Vercel, but this renders even less than what I see on GH pages - which is a bit strange, considering that the demo for the template I use is hosted on Vercel.
I've created a React webpage based on this template. I've tried to deploy this website on GitHub pages as described here, and it does render partially - see here, there are two main issues:
- Only parts of the website render successfully. It seems the ElasticUI components are not properly rendering and
- when I try to navigate to any of the other tabs on the website (e.g. "Speakers"), a 404 error is given.
Running this website on localhost works perfectly, so it seems to be an issue with the deployment on GH Pages. The code can be found here: https://github/kjemist/trikkefestivalen.
I've also tried to deploy this website on Vercel, but this renders even less than what I see on GH pages - which is a bit strange, considering that the demo for the template I use is hosted on Vercel.
Share Improve this question asked Mar 30 at 10:23 Illimar RekandIllimar Rekand 1151 silver badge15 bronze badges1 Answer
Reset to default 3There are 2 things that need to be changed to make things work as expected with github pages.
Github pages don't work with the history API. For a page like yours that has mutliple subpaths to work properly on github pages, you will need to use a Hash routing style. You will have to change
BrowserRouter
toHashRouter
in your code.This change will also add a
#
into your URLs likehttps://kjemist.github.io/trikkefestivalen/#/events
Without this change links to any of your subpaths will fail, i.e.
https://kjemist.github.io/trikkefestivalen/events
will return a 404 if you try to access it directly without navigating to it.When the code is deployed to github pages the base url is a subdirectory
https://kjemist.github.io/trikkefestivalen/
and not the main directory. This requires some changes to navigation that probably were non needed in your template code.There are multiple options here. An ugly one but which requires least amount of changes would be to prepend
process.env.PUBLIC_URL + "#"
whenever you push a path likehistory.push(process.env.PUBLIC_URL + "#/events")
.Better option, you can use
useNavigate
likelet navigate = useNavigate(); const tabs = [ { id: "event", label: t("Event Details"), onClick: () => { navigate("/events"); }, }