在Github Pages上使用Create-React-App返回空白页面

5
当我在本地测试我的create-react-quiz应用程序时,它表现完美。我是基于这个代码来构建项目的:https://github.com/mitchgavan/react-multi-choice-quiz/tree/gh-pages
然而,当我在“GitHub-Pages”分支上使用npm build deploy时,一个空白页面出现了,控制台中显示了以下错误信息: pk8189.github.io/:1 GET pk8189.github.io/pk8189/futureU-/static/css/main.1dc4d41f.css pk8189.github.io/:1 GET pk8189.github.io/pk8189/futureU-/static/js/main.28e294a0.js 这是我的repo: https://github.com/pk8189/futureU-。你认为问题是什么?感谢您提供的任何帮助。
1个回答

11
Create React App使用package.json中的homepage字段来确定应用程序提供服务的URL。由于您将其设置为https://github.com/pk8189/futureU-/,它尝试从不存在的/pk8189/futureU-/请求资源。
homepage更改为匹配您部署的URL:https://pk8189.github.io/futureU-/。然后通过运行npm run build重新构建并重新部署。
这在GitHub Pages的部署说明中有描述。请阅读用户指南的此部分。

非常感谢!现在正在尝试。 - Patrick Kelly
链接已过期,新链接为:https://facebook.github.io/create-react-app/docs/deployment#github-pages-https-pagesgithubcom - Vaibhav Vishal
2
@Dan Abramov:为什么BrowserRouter在gh-pages上不能工作?我试图使用BrowserRouter将react-create-app部署到gh-pages,但只看到一个空白页面。现在我只是用HashRouter替换了BrowserRouter,它的工作非常好。 - Mudassar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接