diff --git a/components/Footer.tsx b/components/Footer.tsx index a3fe7f8..4674d23 100644 --- a/components/Footer.tsx +++ b/components/Footer.tsx @@ -1,37 +1,38 @@ -"use client"; +'use client'; import Image from 'next/image'; import Link from 'next/link'; -import { usePathname, useRouter } from 'next/navigation'; +import { useEffect } from 'react'; +import { usePathname } from 'next/navigation'; export default function Footer() { - const router = useRouter(); const path = usePathname(); + useEffect(() => { + if (typeof window !== 'undefined' && path === '/' && window.location.hash) { + const handleHashChange = () => { + const element = document.querySelector(window.location.hash); + if (element) { + element.scrollIntoView({ behavior: 'smooth' }); + } + }; + + handleHashChange(); // Handle the current hash on load + + window.addEventListener('hashchange', handleHashChange); // Listen for future hash changes + return () => window.removeEventListener('hashchange', handleHashChange); + } + }, [path]); + const navigation = [ { name: 'Home', href: '/' }, - // { name: 'Projects', href: '/projects' }, { name: 'Supporters', href: '/supporters' }, - { name: 'Contact', href: '/#contact' }, + { + name: 'Contact', + href: path === '/' ? '/#contact' : '/?section=contact' + }, ]; - const handleNavigation = (href: string) => { - if (href.includes('#')) { - const [page, section] = href.split('#'); - - if (path === page) { - document.getElementById(section)?.scrollIntoView({ behavior: 'smooth' }); - } else { - router.push(page); - setTimeout(() => { - document.getElementById(section)?.scrollIntoView({ behavior: 'smooth' }); - }, 100); // Adding a small delay to ensure the page has navigated - } - } else { - router.push(href); - } - }; - const socialLinks = [ { name: 'YouTube', @@ -76,15 +77,10 @@ export default function Footer() {