Fixed scroll glitch
This commit is contained in:
@@ -5,7 +5,8 @@
|
|||||||
import { Briefcase, Calendar, FileText, Home as HomeIcon, LifeBuoy, Lock, Map as MapIcon } from 'lucide-react';
|
import { Briefcase, Calendar, FileText, Home as HomeIcon, LifeBuoy, Lock, Map as MapIcon } from 'lucide-react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { usePathname } from 'next/navigation';
|
import { usePathname } from 'next/navigation';
|
||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useLayoutEffect, useRef } from 'react';
|
||||||
|
const useSafeLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
||||||
|
|
||||||
const NavItem = ({ to, icon: Icon, label, className = "" }: { to: string, icon: any, label: string, className?: string }) => {
|
const NavItem = ({ to, icon: Icon, label, className = "" }: { to: string, icon: any, label: string, className?: string }) => {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
@@ -29,7 +30,7 @@ export const Navigation = () => {
|
|||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const navRef = useRef<HTMLElement>(null);
|
const navRef = useRef<HTMLElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useSafeLayoutEffect(() => {
|
||||||
window.scrollTo({ top: 0, behavior: 'instant' });
|
window.scrollTo({ top: 0, behavior: 'instant' });
|
||||||
}, [pathname]);
|
}, [pathname]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user