代码之家  ›  专栏  ›  技术社区  ›  Ryan Howard

为什么我的github.io在页面上显示404?[已关闭]

  •  -3
  • Ryan Howard  · 技术社区  · 1 年前

    我使用react发布到gh页面,尽管我的另一个ryan-howard-hc.github.io/ReactMenu使用相同的教程视频,但它给了我404分?

    https://github.com/ryan-howard-hc/ryan-howard-hc.github.io

    这是回购,它给了我404分,我尝试了我能想到的一切,并与我的其他回购ReactMenu进行了比较

    我采用了同样的方法来部署它。我认为这与它的主页有关 ryan-howard-hc.github.io,但我不知道。请帮忙!

    enter image description here

    2 回复  |  直到 1 年前
        1
  •  0
  •   udoyhasan    1 年前

    你只上传了GitHub存储库中的源代码,它将不起作用。

    如果你想将react网站部署到GitHub页面,请遵循以下步骤:

    方法1:手动部署

    1. 在您的终端中运行此命令:
    cd /change/this/to/your/project/root/directory/path/
    npm run build
    
    1. 然后从您的构建文件夹将所有文件上传到GitHub存储库。仅上传构建文件夹内的内容,

    方法2:直接部署

    1. 添加 gh-pages 包到您的项目
    npm install gh-pages --save-dev
    
    1. 在脚本中的package.json文件中添加 predeploy deploy 属性。
    "scripts": {
      "predeploy": "npm run build",
      "deploy": "gh-pages -d build"
    }
    
    1. 现在将远程git存储库添加到您的项目中: 更改 username repo-name
    git remote add origin https://github.com/{username}/{repo-name}.git
    
    1. 现在将您的react应用程序推送到GitHub存储库
    npm run deploy
    
    1. 最后,当您想要配置子域时,转到设置并选择分支作为 gh页 和root作为 /

    现在,如果你遵循了这2种方法中的任何一种,你的react应用程序都将成功部署到GitHub页面。