react-router4外层路由如何获取子路由的match的path

用的hash,location.hash 是空

//index.js
    <Router>
      <Switch>
        <Route path="/" exact render={() =><Redirect to="/main"/>}/>
        <Route path="/login" exact component={Login} />
        <Route path="/main" component={Main} />
        <Route component={NoMatch} />
      </Switch>
    </Router>

// main.js
<div>    
<Breadcrumb> //这里的match匹配的是/main,如何取到下面的path:/main/child,localtion有pathname但是我需要/main/child/:id这种path
<div>
  <Header/>  
  <Breadcrumb params={this.props} />
  <Route exact path={`${match.url}/index`}  component={ Index } />
  <Route exact path={`${match.url}/base/:id`}  render={ () => <Base {...props} /> 
  <Footer />
</div>
阅读 4k
1 个回答

我用的是hash试了一下,localtion是能匹配到你要的 /main/child/:id 这种path啊,路径是 localtion.hash

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进