【发布时间】:2019-09-29 04:42:29
【问题描述】:
我在我的项目中使用React Router V4,我想要一些像这样的带有不同组件的路由:
/content/:type
/content/view/:id/:title?
我可以这样做吗?怎么样?
【问题讨论】:
标签: reactjs react-router browser-history
我在我的项目中使用React Router V4,我想要一些像这样的带有不同组件的路由:
/content/:type
/content/view/:id/:title?
我可以这样做吗?怎么样?
【问题讨论】:
标签: reactjs react-router browser-history
假设你熟悉 React Router 基础知识,你可以试试这样的。
<BrowserRouter>
<div>
<Route exact path="/content/:type" component={ComponentA} />
<Route exact path="/content/view/:id/:title" component={ComponentB} />
</div>
</BrowserRouter>
在使用组件定义路由之前不要忘记导入组件。
【讨论】: