简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM