【问题标题】:Using react router to route several paths to the same component使用反应路由器将多个路径路由到同一个组件
【发布时间】:2017-10-13 22:09:41
【问题描述】:

我的应用中有以下路线:

<div>
   <Route exact path='/:category' render={() => (
      <Posts/>
   )}/>
   <Route exact path='/' render={() => (
      <Posts/>
   )}/>
</div>

第二个路由只是第一个路由的扩展,并且路由到同一个组件。如何将两条路线合并到一个 Route 标签中?

【问题讨论】:

    标签: reactjs react-router


    【解决方案1】:

    您可以使用&lt;Route exact path='/:category?' component={Posts} /&gt;,问号的作用是将网址扩展名设为可选值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-14
      • 2020-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 2020-01-21
      相关资源
      最近更新 更多