From f99e685eea459857acc7a02b8f9b6a81281208df Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 7 May 2019 16:41:28 +0200 Subject: [PATCH] fix scroll to anchor link on page reload --- scm-ui/src/containers/ScrollToTop.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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); + } } }