Skip to content

Commit

Permalink
fix(gatsby-react-router-scroll): fix issues with anchor links (#37498)
Browse files Browse the repository at this point in the history
Co-authored-by: Mitchell Bennett <[email protected]>
Fixes #28555
  • Loading branch information
sapiensfio authored Jan 19, 2023
1 parent fe65c29 commit e7e5cb4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/gatsby-react-router-scroll/src/scroll-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ export class ScrollHandler extends React.Component<
scrollPosition = this._stateStorage.read(this.props.location, key)
}

if (scrollPosition) {
this.windowScroll(scrollPosition, undefined)
} else if (hash) {
/** If a hash is present in the browser url as the component mounts (i.e. the user is navigating
* from an external website) then scroll to the hash instead of any previously stored scroll
* position. */
if (hash) {
this.scrollToHash(decodeURI(hash), undefined)
} else if (scrollPosition) {
this.windowScroll(scrollPosition, undefined)
}
}

Expand Down

0 comments on commit e7e5cb4

Please sign in to comment.