reactjs - 如何修复 GitHub Pages 中的反应框架错误
问题描述
我正在学习 React 并在 Github 中设置一个 repo,它位于https://github.com/chenjianAgain/ContactManager_Source.git。
我使用 npm run build 在我的笔记本电脑中生成构建目录。并且服务构建工作正常。
但是当我将整个构建目录复制到下面的新仓库时,Github Pages 无法访问它。https://github.com/chenjianAgain/ContactManager_Destination.git。
有人可以帮助我吗?非常感谢。
https://github.com/chenjianAgain/ContactManager_Source.git。
源代码在我的笔记本电脑上运行良好。
serve build
也适用于我的笔记本电脑。
https://github.com/chenjianAgain/ContactManager_Destination.git。
但是当我将所有文件从 /build 复制到上面的 repo 时,Github Pages 不起作用。
解决方案
转到您的 package.json 并添加此属性
"homepage": "http://username.github.io/myapp"
我的猜测是你错过了这一步。
此外,如果您使用的是 react-router,如果您在应用程序上使用子目录,则必须添加基本名称。
<BrowserRouter basename="/myapp">
<App />
</BrowserRouter>,
推荐阅读
- r - 在R测试中,如果案例在一个时间范围内并且是一个唯一的ID
- floating-point - 在这里避免浮点计算错误的最佳方法是什么?
- javascript - RTL 的 TypeError:_react2.screen.getAllBy 不是函数
- function - 我们可以用 C# 中的变量替换函数名吗
- c# - 如何将数据发布到 .net core restApi 中的多个表?
- javascript - 如何确认密码以更改密码并在 api 中发布?
- python - 在 Python 中渲染像素的最基本方法是什么?
- flutter - 添加动态滑块值以列出和打印它们并将它们作为帖子发送到服务器
- node.js - Express 4.17 req.body 为空
- react-native - 在堆栈导航器托管的屏幕内访问“headerRight”