fix(v2): restore previous scroll position on back button click (#5081)

This commit is contained in:
Alexey Pyltsyn 2021-06-29 16:31:25 +03:00 committed by GitHub
parent 7592982960
commit 7fe2a9891d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@
*/
import React, {useRef} from 'react';
import {useHistory} from '@docusaurus/router';
import Translate from '@docusaurus/Translate';
import {useLocationChange} from '@docusaurus/theme-common';
@ -19,6 +20,7 @@ function programmaticFocus(el: HTMLElement) {
function SkipToContent(): JSX.Element {
const containerRef = useRef<HTMLDivElement>(null);
const {action} = useHistory();
const handleSkip = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
@ -32,7 +34,7 @@ function SkipToContent(): JSX.Element {
};
useLocationChange(({location}) => {
if (containerRef.current && !location.hash) {
if (containerRef.current && !location.hash && action !== 'POP') {
programmaticFocus(containerRef.current);
}
});