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