【问题标题】:Create-React-App on Github-pages returns a blank pageGithub 页面上的 Create-React-App 返回一个空白页面
【发布时间】:2017-07-02 23:07:57
【问题描述】:

在本地测试时,我的 create-react-quiz 应用程序运行良好。我的项目基于以下代码:https://github.com/mitchgavan/react-multi-choice-quiz/tree/gh-pages

但是,当我在“GitHub-Pages”分支上使用 npm build deploy 时,会出现一个空白页面,并且控制台中会显示以下错误: pk8189.github.io/:1 获取 pk8189.github.io/pk8189/futureU-/static/css/main.1dc4d41f.css pk8189.github.io/:1 获取 pk8189.github.io/pk8189/futureU-/static/js/main.28e294a0.js

这是我的仓库:https://github.com/pk8189/futureU- 你认为问题是什么?感谢您的帮助。

【问题讨论】:

    标签: javascript reactjs github-pages create-react-app


    【解决方案1】:

    Create React App 使用 package.json 中的 homepage 字段来确定提供应用程序的 URL。由于您set it to https://github.com/pk8189/futureU-/,它会尝试从不存在的/pk8189/futureU-/ 请求资产。

    更改 homepage 以匹配您部署的 URL:https://pk8189.github.io/futureU-/。然后通过运行npm run build 重建并重新部署。

    这在deployment instructions for GitHub Pages 中有描述。请阅读用户指南的这一部分。

    【讨论】:

    • 非常感谢!现在试试。
    • 链接已过期,新链接:facebook.github.io/create-react-app/docs/…
    • @Dan Abramov:为什么 BrowserRouter 不能使用 gh-pages?我试图使用 BrowserRouter 将 react-create-app 部署到 gh-pages 但只看到一个空白页面。现在我只是用 HashRouter 替换 BrowserRouter,它工作得很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 2019-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多