Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!