首页 > 解决方案 > 在 Github.io 上看不到任何组件

问题描述

当我在github.io上创建 React 项目时,我在 Chrome 中看不到任何组件。
在“myUserName.github.io”存储库中,有一个通用的 HTML 文件。存储库中的一个目录是我的 React 项目文件夹:

在此处输入图像描述

和 HTML 文件:

在此处输入图像描述

像这些图片,<div id="root">是空的。但是当我在 上使用它时localhost,它确实运行。

可能是什么问题呢?

------------------- 添加源代码 -----------------------

目录 :

__ index.html (1)
|__ 反应 __ 太空旅行 __ 构建 __ 静态 __ ...
。. . . . . . . . . . . . . . . . . | . . . . . . |__ 索引.html
。. . . . . . . . . . . . . . . . . |__ 节点模块 __ ...
. . . . . . . . . . . . . . . . . . |__ 公共 __ index.html (2)
。. . . . . . . . . . . . . . . . . |__ src __ App.js
。. . . . . . . . . . . . . . . . . |。. . . . |__ index.js (3)
。. . . . . . . . . . . . . . . . . |。. . . . |__ registerServiceWorker.js
。. . . . . . . . . . . . . . . . . |__package.json

(1) 项目的 index.html :

<!DOCTYPE html>
...
<body>
    <div>Index Page</div>
    <a href='./react/space-trip/public/index.html'>Go</a>
    <a href='./react/space-trip/build/index.html'>Go - build</a>
</body>
</html>

(2) public/index.html :

<!DOCTYPE html>
<html lang='en'>
    <head>
    ...
    </head>
    <body>
        <noscript>
            You need to enable JavaScript to run this app.
        </noscript>
        <div id='root'></div>
    </body>
</html>

(3) index.js :

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

构建此项目后,我将 url 添加到 [build]-[index.html],它也是空的。我也试过在没有 registerServiceWorker 的情况下运行这个页面,但它是一样的。

标签: reactjsgithub

解决方案


推荐阅读