reset scroll position on path change
This commit is contained in:
@ -20,6 +20,7 @@ export const Header = () => {
|
|||||||
setShowMenu(!showMenu);
|
setShowMenu(!showMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove ability to scroll when opening menu + keep previous scroll position when closing menu
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (showMenu) {
|
if (showMenu) {
|
||||||
const scrollY = window.scrollY;
|
const scrollY = window.scrollY;
|
||||||
@ -33,9 +34,16 @@ export const Header = () => {
|
|||||||
}
|
}
|
||||||
}, [showMenu]);
|
}, [showMenu]);
|
||||||
|
|
||||||
|
// reset scroll position on path change
|
||||||
|
useEffect(() => {
|
||||||
|
if (!showMenu) {
|
||||||
|
window.scrollTo(0, 0);
|
||||||
|
}
|
||||||
|
}, [location.pathname, showMenu]);
|
||||||
|
|
||||||
|
// hide menu and reset active menu item on path change
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// hide menu on path change
|
|
||||||
setShowMenu(false);
|
setShowMenu(false);
|
||||||
setActiveMenuItem(undefined);
|
setActiveMenuItem(undefined);
|
||||||
}, [pathname]);
|
}, [pathname]);
|
||||||
|
Reference in New Issue
Block a user