我正在尝试将我的 git repo 与一个练习 React 应用程序一起放入 codeandbox.io,以便我可以更轻松地向其他人展示它。我按照这里的说明进行操作:https ://codesandbox.io/s/github/cdpautsch/react-learning-area/tree/master/test-app2
但是,我收到错误:Target container is not a DOM element
evaluate
/src/index.js:52:9
49 | }
50 | }
51 |
> 52 | ReactDOM.render((
| ^
53 | <Provider store={store}>
54 | <BrowserRouter>
55 | <div>
当我使用 webpack-dev-server 运行时,此错误不会出现在我的机器上。
我的代码来自index.js
:
ReactDOM.render((
<Provider store={store}>
<BrowserRouter>
<div>
<Navbar />
<Route exact path = "/" component = {Home} />
<Route path = "/cards" component = {CardsGame} />
</div>
</BrowserRouter>
</Provider>
), document.getElementById('app'));
我的代码来自index.html
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>TestApp2</title>
</head>
<body>
<div id="app"></div>
</body>
</html>
它说它不是一个有效的元素,但它肯定存在并且肯定有正确的名称。我错过了什么?
使用附加信息进行更新: * 应用程序不是用 . 创建的create-react-app
,而是手动初始化和加载包 * 沙盒似乎默认为 CRA,这可能会影响它的运行方式?