Mag*_*dal 4 reactjs react-router react-router-v4
我是使用React Router v4的新手,目前正在以下场景中挣扎
<Route exact path="/campaign/new" component={CampaignEditor}/>
<Route exact path="/campaign/:id" component={Campaign}/>
Run Code Online (Sandbox Code Playgroud)
我想要精确匹配/campaign/new进行渲染CampaignEditor。在其他所有情况下,我都希望Campaign使用动态ID作为参数进行渲染。
如果参数等于“ new”,我当然可以在广告系列组件中呈现编辑器,但是有没有办法使用路由器呢?
利用,Switch您可以渲染诸如
<Router>
<Switch>
<Route exact path="/campaign/new" component={CampaignEditor}/>
<Route path="/campaign/:id" component={Campaign}/>
</Switch>
</Router>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
486 次 |
| 最近记录: |