Using GitHub pages, blank white screen

我是研究僧i 提交于 2020-02-06 11:29:56

问题


I'm trying to make a react project on github pages using [username].github.io. but when I go on the link, it just returns a white screen without any error messages. This also happens when I use a custom domain name.

However, it works when I run it locally and also when I use gh-pages instead of a user repo.

I used https://medium.freecodecamp.org/surge-vs-github-pages-deploying-a-create-react-app-project-c0ecbf317089 to upload all my files into github since I created the repo at the end after I finished, but I tweaked it a little to work without gh-pages.

I also referred to this answer: hosting gh-pages on custom domain, white empty page but it didn't do anything for me.

Does anyone know how to fix this? Thanks!


回答1:


Change BrowserRouter to HashRouter as follow

Before:

import { BrowserRouter } from "react-router-dom"

ReactDOM.render(
    <BrowserRouter><App /></BrowserRouter>,
    document.getElementById('root')
);

After:

import { HashRouter } from "react-router-dom"

ReactDOM.render(
    <HashRouter><App /></HashRouter>,
    document.getElementById('root')
);



回答2:


Check if you're getting an error on the console. You might need to switch from BroswerRouter to HashRouter, because gh-pages doesn't work well with the former.



来源:https://stackoverflow.com/questions/47986545/using-github-pages-blank-white-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!