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

120
Visualizações
Gatsby location props not available

According to the Gatsby docs the location props should be available to all components https://www.gatsbyjs.com/docs/location-data-from-props/.

My pages are under src/pages and are automatically routed using the <Link> inside the header component. However, the below code in the header component returns undefined:

const Header = ({ location }) => {

console.log(location)

Am i missing something? Do i need to explicitly pass down location props to header? As i interpreted the docs, this is done automatically.

An idea had - could it be due to my {children} pass in layout.js?

Layout.js

return (
<>
  <Header url={data.site.siteMetadata.siteUrl} />
  
  <main>{children}</main>

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

location property is available in top-level components (pages) so you should get it into a page and drill down into your Header or another component. As it is extracted from the docs:

Sometimes it can be helpful to know exactly what your app’s browser URL is at any given stage. Because Gatsby uses @reach/router for client-side routing, the location prop is passed to any page component and represents where the app is currently

Because Gatsby extends from @reach/router, you can take advantage by using a Layout as a page component, in that case, location will be available in your Layout component, from there, you can lift it down to any desired children component.

In your scenario, the Header component by default, will never have the location data, you should have to pass it from where it's available.

about 4 years ago · Juan Pablo Isaza 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