连接路由器错误,路由器可能只有一个子元素

IT技术 reactjs redux react-router
2021-05-21 06:35:49
ReactDOM.render(
  <Provider store={store}>
    <ConnectedRouter history={history}> { /* place ConnectedRouter under Provider */}
      <div>
        <Switch>
          <Route exact={true} path="/enthusiasm" component={Hello} />
          <Route exact={true} path="/shipments" component={ShipmentsTable} />
          <Route exact={true} path="/shipments/:pickUpId" component={ShipmentInfoPage} />
        </Switch>
      </div>
    </ConnectedRouter>
  </Provider>
  ,
  document.getElementById('root') as HTMLElement
);

这给了我一个错误说, A <Router> may have only one child element, and it has only one element.

一切都根据连接路由器存储库中的示例

这与 BrowserRouter 一起工作正常,任何帮助。

版本信息

  • 连接react-router“4.4.1”,
  • react-router:“4.3.1”,
  • react:“16.4.2”
2个回答

这主要是您正在渲染的组件之一出现错误,或者是您正在使用的包版本错误。首先,我将删除您的 node_modules 文件夹,接下来,确保使用此 package.json 文件正在使用的所有依赖版本接下来,在您的项目上运行 npm install 或 yarn add。

如果这不起作用,请将您正在使用的组件插入原始帖子,尤其是渲染链接和路由的组件。

在我将空格更改为制表符之前,我遇到了这个问题。不知道为什么)