React Router v4中的动态嵌套路由

时间:2018-10-01 14:02:22

标签: reactjs react-router

我有一个项目层次结构。假设它是“国家”->“地区”(仅作为示例)。 所以我想有这样的路线:

/countries/germany            // list of regions
/countries/germany/1          // region details in Germany
/countries/germany/1/stores   // list of stores in region #1 Germany

这是根路由:

  <Router history={history}>
    <Switch>
      <Route path='/countries' component={CountriesRoot} />
      <Route><Redirect to='/countries' /></Route>
    </Switch>
  </Router>

还有CountriesRoute

const CountriesRoot = ({ match }) => (
  <Switch>
    <Route exact path={match.url} component={CountriesList} />
    <Route path={`${match.url}/:id(create|\d+)`} component={SingleCountryRoot} />
    <Route><Redirect to={match.url} /></Route>
  </Switch>
)

显然这条路线有问题:

<Route path={`${match.url}/:id(create|\d+)`} component={SingleCountryRoot} />

路线/countries/germany/1不起作用。我误解了React Router的理念吗?

0 个答案:

没有答案