Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
React-router v4 - display current page

I have a main component, App that holds all my Match components. I'd like to be able to display the current page at the top (in header, for example) but I'm having trouble getting the current pathname.

In App I have:

App.contextTypes = {
  history: React.PropTypes.object,
};

And I pass the current path name to a component:

<Header currentPathname={this.context.history.location.pathname} />

However, App doesn't seem to update when the location changes. How can I listen for this and pass as a prop?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Presumably you want your header to show on all routes, if you're putting it above your Match components. In that case, also use Match for your header, and match on every pattern and you will have access to location through props.

<Match 
  pattern="/" 
  component={props => <Header pathname={props.location.pathname} />}
/>
over 4 years ago · Santiago Trujillo Relatório

0

Match is not a component anymore in react-router-dom (^4.3.1). Instead, I did this:

<Route path="" component={(props) => <Header {...props} page={"Main Page"} />}/>

In Header.js:

const Header = (props) => (
  <header className="App-header">
  { console.log(props) }
    <img src={logo} className="App-logo" alt="logo"/>
    <TitleDiv>App Name : {props.page}</TitleDiv>
  </header>
);

The result is App Name : Main Page

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda