React Router with Github Pages 💎

medaminefh

Mohamed Amine Fh

Posted on September 18, 2021

React Router with Github Pages 💎

If you have tried to deploy a React App with react-router-dom to github pages, probably you'll hate yourself because it won't work as you expected 😔.

So what the heck is going on ? why is this happening?

So if you don't know gh-pages deploy your React App
to this url http://{username}.github.io/{repo-name}
and in your App the "/" route means this url http://{username}.github.io/.

So one solution for this

is to replace the BrowserRouter with HashRouter
so instead of this
BrowserRouter

do this

HashRouter

Now deploy again your changes with
npm run deploy

Thats it

💖 💪 🙅 🚩
medaminefh
Mohamed Amine Fh

Posted on September 18, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related