【问题标题】:Issue with connected-react-router连接反应路由器的问题
【发布时间】:2020-04-25 16:26:21
【问题描述】:

我使用 connected-react-router 创建了以下路由,如下所示

<Switch>
    <Route exact={true} path="/a" component={A}/>
    <Route exact={true} path="/b" component={B}/>
    <Route path="/c/:id" component={C}/>
</Switch>

但是当我点击 url my.domain.com/c 时,组件没有得到渲染。但是当我去给 url my.domain.com/c/12 时,它就可以工作了。我也尝试过设置 exact={false} 。它仍然不起作用。任何帮助都将帮助我更进一步。

【问题讨论】:

    标签: react-router react-router-dom connected-react-router


    【解决方案1】:

    当你声明路由时:

    <Route path="/c/:id" component={C}/>
    

    您是说“id”是强制性的。如果即使用户不传递id也需要渲染页面,则需要添加“?”:

    <Route path="/c/:id?" component={C}/>
    

    【讨论】:

      猜你喜欢
      • 2021-08-11
      • 2017-03-24
      • 1970-01-01
      • 2020-12-21
      • 2021-11-25
      • 2018-07-07
      • 2021-02-21
      • 1970-01-01
      • 2017-11-06
      相关资源
      最近更新 更多