connected-router error, a router may have only one child element

倾然丶 夕夏残阳落幕 提交于 2019-12-13 02:27:42

问题


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
);

this is giving me an error saying, A <Router> may have only one child element, and it has only one element.

everything is according to the example in connected-router repo

and this was working fine with BrowserRouter, any help.

Version Info

  • connected-react-router "4.4.1",
  • react-router: "4.3.1",
  • react: "16.4.2"

回答1:


This is most either an error with one of the components you are rendering, or is an error with the package versions you are using. First, I would remove your node_modules folder, next, make sure to use all the dependency versions that this package.json file is using Next, run npm install or yarn add on your project.

If this does not work, please insert the components you are using into the origin post, especially ones that render links and routes.




回答2:


i had this issue until i change spaces to tabs. Don't know why)



来源:https://stackoverflow.com/questions/51834177/connected-router-error-a-router-may-have-only-one-child-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!