【问题标题】:Similar URI but different components - React Router V4相似的 URI 但不同的组件 - React Router V4
【发布时间】:2019-09-29 04:42:29
【问题描述】:

我在我的项目中使用React Router V4,我想要一些像这样的带有不同组件的路由:

/content/:type

/content/view/:id/:title?

我可以这样做吗?怎么样?

【问题讨论】:

    标签: reactjs react-router browser-history


    【解决方案1】:

    假设你熟悉 React Router 基础知识,你可以试试这样的。

    <BrowserRouter>
      <div>
        <Route exact path="/content/:type" component={ComponentA} />
        <Route exact path="/content/view/:id/:title" component={ComponentB} />
      </div>
    </BrowserRouter>
    

    在使用组件定义路由之前不要忘记导入组件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-10
      • 2017-08-29
      • 1970-01-01
      • 2018-08-06
      • 1970-01-01
      • 2018-08-25
      • 2019-01-15
      • 2018-01-10
      相关资源
      最近更新 更多