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

发布于 2022-09-11 14:36:47 字数 804 浏览 20 评论 0

用的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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伊面 2022-09-18 14:36:47

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文