mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-03 19:32:35 +02:00
fix(v2): do not focus on skip link if page refreshed (#4797)
* fix(v2): do not focus on skip link if page refreshed * rename ref Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
ab19070ab5
commit
0360364570
4 changed files with 32 additions and 9 deletions
21
packages/docusaurus-theme-common/src/utils/useChangeRoute.ts
Normal file
21
packages/docusaurus-theme-common/src/utils/useChangeRoute.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {useRef, useEffect} from 'react';
|
||||
import {useLocation} from '@docusaurus/router';
|
||||
|
||||
export function useChangeRoute(onRouteChange: () => void): void {
|
||||
const {pathname} = useLocation();
|
||||
const latestPathnameRef = useRef(pathname);
|
||||
|
||||
useEffect(() => {
|
||||
if (pathname !== latestPathnameRef.current) {
|
||||
latestPathnameRef.current = pathname;
|
||||
onRouteChange();
|
||||
}
|
||||
}, [pathname, latestPathnameRef, onRouteChange]);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue