【问题标题】:React Github pages says published but I keep getting a 404React Github 页面说已发布,但我一直收到 404
【发布时间】:2020-06-22 00:03:45
【问题描述】:

我正在尝试按照this link 上的步骤将 React 应用程序部署到 Github 页面。我完全按照这些步骤操作,我的package.json 看起来像这样:

{
    "homepage": "https://sohaib94.github.io/cv",
    "name": "web",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "@testing-library/jest-dom": "^4.2.4",
        "@testing-library/react": "^9.5.0",
        "@testing-library/user-event": "^7.2.1",
        "react": "^16.13.1",
        "react-dom": "^16.13.1",
        "react-scripts": "3.4.1",
        "react-spring": "^8.0.27"
    },
    "scripts": {
        "predeploy": "npm run build",
        "deploy": "gh-pages -d build",
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
    },
    "eslintConfig": {
        "extends": "react-app"
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
        ]
    },
    "devDependencies": {
        "gh-pages": "^3.1.0"
    }
}

然后我使用npm run deploy 部署应用程序。这会正确创建一个分支gh-pages

我的仓库有正确的设置(设置说Your site is ready to be published at http://sohaib94.github.io/cv/.,下面的来源说Your GitHub Pages site is currently being built from the gh-pages branch.)所以我假设我做的一切都正确,但我的页面仍然得到404(http://sohaib94.github.io/cv/)。

我在这里做错了什么吗?

谢谢

【问题讨论】:

  • 转到...github.io/cv/index.html 看看是否正确加载,我之前遇到过同样的问题。
  • 嗨,Rodentman87,我试过了,但不幸的是没有运气

标签: reactjs github github-pages


【解决方案1】:

确保对于您的 GitHub 存储库设置,you have selected the gh-pages branch

publication sources而言,项目站点也可以从master分支或master分支上的/docs文件夹发布。

所以指定来源很重要。

【讨论】:

  • 嗨@VonC 我已将 gh-pages 设置为发布源的分支,并检查了该分支是否存在并且有一个 index.html 文件但仍然没有运气
  • @sohaib 很奇怪。我确实看到了github.com/sohaib94/cv/tree/gh-pages。存储库设置页面中必须缺少或未选择设置(在发布源旁边)。
  • 嘿@VonC,感谢您的帮助。意识到我正在拨打网络电话,但这是不允许的,因此删除它并再次尝试它可以正常工作 - 感谢您的耐心等待!
【解决方案2】:

所以找到了我的问题的答案 - 我正在进行网络调用以加载一些图像,但没有意识到 github 页面不允许这样做。

下载图像并放入我的资产文件夹并删除网络调用,嘿,很快,一切都很好。

感谢所有试图提供帮助的人

【讨论】:

    猜你喜欢
    • 2020-11-15
    • 2019-04-08
    • 2021-01-12
    • 2021-11-28
    • 1970-01-01
    • 2017-04-11
    • 1970-01-01
    • 1970-01-01
    • 2023-02-12
    相关资源
    最近更新 更多