网站在部署后显示空白页面

时间:2019-11-20 14:34:44

标签: reactjs github deployment github-pages

我是React的新手,这是我第一次尝试使用Github页面部署我的网站。

我按照所有说明进行了操作,确实做了需要做的事情,但是问题是我看到一个空白页...

有人可以帮我吗?

这是我的仓库:Eloquent model

3 个答案:

答案 0 :(得分:0)

一种简单的方法是安装gh-pages npm软件包。您必须在homepage中设置package.json,例如"homepage": "link-to-repo"

然后将脚本添加到您的包中,例如:

"deploy": "gh-pages -d build",

您的脚本应类似于

"scripts": {    
   "start": "react-scripts start",
   "predeploy": "yarn run build",
   "deploy": "gh-pages -d build",
   "build": "react-scripts build",
   "test": "react-scripts test",
   eject": "react-scripts eject"
},

答案 1 :(得分:0)

路由器中的

path='/'意味着您实际上在匹配/(例如https://lidorb94.github.io/),但实际上您的项目在https://lidorb94.github.io/instagram-ui/上。像这样将process.env.PUBLIC_URL用作BrowserRouter上的基本名称道具;

<BrowserRouter basename={process.env.PUBLIC_URL}>
  {/* routes */}
</BrowserRouter>

答案 2 :(得分:0)

我假设您已经在package.json文件中添加了以下几行,并且npm运行build

"homepage":"https://{Your_Github_Username}.github.io/{repo-name}", //outside dependencies

"scripts": {
    .
    .
    "predeploy":"npm run build",
    "deploy":"gh-pages -d build"
}

如果这不起作用,请检查控制台,是否发现任何错误。

在控制台中看到错误后,我能够解决此问题。就我而言,错误是与https请求有关。当我将它更改为“ https”时,已在index.html中使用“ http”添加了一个脚本链接,效果很好。

发现错误后,请不要忘记提交并推送更改,然后再次运行deploy ...