React Router v4 – How to get current route?

I’d like to display a title in <AppBar /> that is somehow passed in from the current route.

In React Router v4, how would <AppBar /> be able to get the current route passed into it’s title prop?

  <Router basename="/app">
    <main>
      <Menu active={menu} close={this.closeMenu} />
      <Overlay active={menu} onClick={this.closeMenu} />
      <AppBar handleMenuIcon={this.handleMenuIcon} title="Test" />
      <Route path="/customers" component={Customers} />
    </main>
  </Router>

Is there a way to pass a custom title from a custom prop on <Route />?

8 Answers
8

Leave a Comment