diff --git a/packages/docusaurus-theme-common/src/utils/useLocationChange.ts b/packages/docusaurus-theme-common/src/utils/useLocationChange.ts index 89cc27be455e..1aeaf69f0bd7 100644 --- a/packages/docusaurus-theme-common/src/utils/useLocationChange.ts +++ b/packages/docusaurus-theme-common/src/utils/useLocationChange.ts @@ -25,6 +25,10 @@ export function useLocationChange(onLocationChange: OnLocationChange): void { const onLocationChangeDynamic = useDynamicCallback(onLocationChange); useEffect(() => { + if (!previousLocation) { + return; + } + if (location !== previousLocation) { onLocationChangeDynamic({ location,