如果找到完全匹配则覆盖动态路由

Override dynamic route if exact match is found

我对使用 React Router v4 还很陌生,目前正在努力应对以下情况

<Route exact path="/campaign/new" component={CampaignEditor}/>
<Route exact path="/campaign/:id" component={Campaign}/>

我想要完全匹配 /campaign/new 去渲染 CampaignEditor。在所有其他情况下,我想使用动态 id 作为参数呈现 Campaign

如果参数等于 "new",我当然可以在活动组件中呈现编辑器,但是有没有办法用路由器来做到这一点?

利用Switch,你可以像

一样渲染路线
<Router>
     <Switch>
          <Route exact path="/campaign/new" component={CampaignEditor}/>
          <Route path="/campaign/:id" component={Campaign}/>
     </Switch>
</Router>