UNPKG

@newrelic/gatsby-theme-newrelic

Version:

[![Community Project header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Project.png)](https://opensource.newrelic.com/oss-category/#community-project)

28 lines (25 loc) 895 B
const shouldUpdateScroll = ( { routerProps, getSavedScrollPosition, prevRouterProps }, themeOptions ) => { // Ensures no scrolling ever when search modal is open const params = new URLSearchParams(window?.location?.search); if (params.has('q')) { return false; } // If the 'shouldUpdateScroll' theme option exists and is one of the listed routes // OR if a user is changing pages/urls, allow for scrolling to top... if ( routerProps?.location?.pathname !== prevRouterProps?.location?.pathname || (themeOptions?.shouldUpdateScroll && themeOptions.shouldUpdateScroll.routes.some((route) => routerProps?.location?.pathname.startsWith(route) )) ) { const currentPosition = getSavedScrollPosition(routerProps?.location); return currentPosition || [0, 0]; } // ...otherwise, don't return false; }; export default shouldUpdateScroll;