Gatsby: Are there page change handlers?

Created on 13 Sep 2018  路  2Comments  路  Source: gatsbyjs/gatsby

If not, how could I go about setting these up?

Just want to execute arbitrary code upon page load - for every page.

Most helpful comment

You can do this inside gatsby-browser.js with onRouteUpdate:

gatsby-browser.js
exports.onRouteUpdate = ({ location }) => {
  console.log('new pathname', location.pathname)
}

All 2 comments

You can do this inside gatsby-browser.js with onRouteUpdate:

gatsby-browser.js
exports.onRouteUpdate = ({ location }) => {
  console.log('new pathname', location.pathname)
}

Wow. That's nifty.

Thanks

Was this page helpful?
0 / 5 - 0 ratings