我正在学习React并在Github中设置一个仓库,该仓库位于https://github.com/chenjianAgain/ContactManager_Source.git 。
我使用npm run build在笔记本电脑中生成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复制到上面的存储库时,Github Pages不起作用。
转到您的package.json并添加此属性
"homepage": "http://username.github.io/myapp"
我的猜测是您错过了这一步。
另外,如果您使用的是react-router,则如果您在应用程序上使用子目录,则必须添加一个基本名称。
<BrowserRouter basename="/myapp">
<App />
</BrowserRouter>,