Search code examples
reactjsreact-routergithub-pagescreate-react-app

Changing to custom domain on Github Pages causes create-react-app with react-router to stop working


So my app, /portfolio, works fine when deployed to the normal github hosting. You can see that here. But when I switch to a custom domain the app doesn't want to mount. I did a bit of research and assumed it has to do with react-router but I can't seem to figure it out.

Heres my BrowserRouter code:

<BrowserRouter basename={process.env.PUBLIC_URL}>
  <App />
</BrowserRouter>,

Which leaders to /portolio/ as the basename. I assume it should correctly change when on the custom domain but I played with it to no effect.

Any hints on what could be going wrong?


Solution

  • Turns out create-react-app docs actually highlight this problem. Github pages doesn't play well with BrowserRouter. Theres a sort of hack in the documents here that worked swimmingly for me.