diff --git a/scm-ui/src/containers/ScrollToTop.js b/scm-ui/src/containers/ScrollToTop.js index d48ea6531a..77054b8463 100644 --- a/scm-ui/src/containers/ScrollToTop.js +++ b/scm-ui/src/containers/ScrollToTop.js @@ -11,7 +11,15 @@ type Props = { class ScrollToTop extends React.Component { componentDidUpdate(prevProps) { if (this.props.location.pathname !== prevProps.location.pathname) { - window.scrollTo(0, 0); + const hash = this.props.location.hash; + if (hash) { + const element = document.getElementById(hash.substring(1)); + if (element && element.scrollIntoView) { + element.scrollIntoView(); + } + } else { + window.scrollTo(0, 0); + } } }