connected-router error, a router may have only one

2019-08-03 02:51发布

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"

2条回答
来,给爷笑一个
2楼-- · 2019-08-03 03:10

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.

查看更多
够拽才男人
3楼-- · 2019-08-03 03:20

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

查看更多
登录 后发表回答