我在github页面上部署了我的react应用,我的网站使用了多个API来显示内容。当我在github页面上部署我的React应用程序时,该网站是空的。我遇到的另一个问题是在重定向到另一条路由时,例如:https://username.github.io/movies甚至是https://username.github.io/website/movies,我收到此错误:
404
There isn't a GitHub Pages site here.
If you're trying to publish one, read the full documentation to learn how to set up GitHub Pages for your repository, organization, or user account.
我的package.json:
"homepage": "https://username.github.io/website",
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
}
答案 0 :(得分:0)
如果您确保对链接而不是真实链接使用历史记录操作,则可以在Github页面上运行react应用。您可以编写自己的链接组件,该组件包装一个标签并执行一个history.push点击而不是让浏览器处理链接,或者您可以使用react-router中的HashRouter之类的东西。
如果有人通过/ something链接进入您的网站,则github将尝试从您的存储库中加载相应的文件,而该文件不存在。
这也意味着到您网站的任何直接/热链接仅适用于静态页面,不适用于您的React App动态生成的内容。