如何修复GitHub Pages中的React Framework错误

问题描述 投票:0回答:1

我正在学习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不起作用。

reactjs github
1个回答
0
投票

转到您的package.json并添加此属性

    "homepage": "http://username.github.io/myapp" 

我的猜测是您错过了这一步。

另外,如果您使用的是react-router,则如果您在应用程序上使用子目录,则必须添加一个基本名称。

    <BrowserRouter basename="/myapp">
      <App />
    </BrowserRouter>,
© www.soinside.com 2019 - 2024. All rights reserved.