fix scroll to anchor link on page reload

This commit is contained in:
Sebastian Sdorra
2019-05-07 16:41:28 +02:00
parent 6d325f56e1
commit f99e685eea

View File

@@ -11,7 +11,15 @@ type Props = {
class ScrollToTop extends React.Component<Props> {
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);
}
}
}