-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example for gatsby-browser.js API shouldUpdateScroll #3857
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,11 @@ exports.onRouteUpdate = true | |
* @param {object} $0 | ||
* @param {object} $0.prevRouterProps The previous state of the router before the route change. | ||
* @param {object} $0.pathname The new pathname | ||
* @example | ||
* exports.shouldUpdateScroll = (prevRouterProps, pathname) => { | ||
* window.scrollTo(0, 0) // upon navigation, scroll to top of page | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious what the use case for doing this would be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my particular use-case, I wanted it so when navlinks clicked always start at the top of the page. By default, they start off at the last scrolled position of the page. This example overrides that behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you try upgrading to the latest Gatsby? There was a bug that was causing problems with scrolling that I fixed in #3775 It sounds like you were just running into that bug. I'd love an example for this API but it should be a realistic one — not one that works around a bug :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood! I'll remove my workaround, and then test. If I come up with a better example, I will absolutely submit. Thanks for the update, Kyle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just confirming you fixed the issue I was having with your patch. |
||
* return false | ||
* }; | ||
*/ | ||
exports.shouldUpdateScroll = true | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you do this in a separate PR? Thanks!