连接路由器错误,路由器可能只有一个子元素 [英] connected-router error, a router may have only one child element

查看:70
本文介绍了连接路由器错误,路由器可能只有一个子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ReactDOM.render(<提供者商店={商店}><ConnectedRouter history={history}>{/* 将 ConnectedRouter 放在 Provider 下 */}<div><开关><路由精确={true} path="/enthusiasm" component={Hello}/><Route exact={true} path="/shipments" component={ShipmentsTable}/><Route exact={true} path="/shipments/:pickUpId" component={ShipmentInfoPage}/></开关>

</ConnectedRouter></提供者>,document.getElementById('root') 作为 HTMLElement);

这给了我一个错误说,一个<路由器>可能只有一个子元素,它也只有一个元素.

一切都根据connected-router repo中的示例进行

这在 BrowserRouter 上运行良好,任何帮助.

版本信息

  • 连接反应路由器4.4.1",
  • 反应路由器:4.3.1",
  • 反应:16.4.2"

解决方案

这很可能是您渲染的组件之一出现错误,或者是您使用的包版本错误.首先,我会删除你的 node_modules 文件夹,接下来,确保使用 这个 package.json 文件 正在使用接下来,在您的项目上运行 npm install 或 yarn add.

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

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"

解决方案

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.

这篇关于连接路由器错误,路由器可能只有一个子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆