I am having the problem discussed in the React Create App docs about how routers that use the HTML5 pushState history API will fail on static file servers without configuring it to serve index.html everytime. How can I fix this problem while using github pages? Also I’m not using the Create React App or react-scripts
I have tried adding a basename to the BrowserRouter component
<BrowserRouter basename={process.env.PUBLIC_URL}>
Much better explanation of the problem here:
2
Answers
When using
react-router-dom
with GitHub pages, you’ll need to useHashRouter
instead ofBrowserRouter
. It uses the#
fragment of the URL to keep the route, circumventing the lack of support forpushState
on GH pages.(There are some awkward ways to make
pushState
for GitHub pages, but I don’t personally recommend them. Here’s a guide for that)I resolve this problem use HashRouter.