Skip to content

Commit

Permalink
solved ohcnetwork#20 i.e contact link is now working from other than …
Browse files Browse the repository at this point in the history
…homepage
  • Loading branch information
thecodephilic-guy committed Nov 12, 2024
1 parent aaba91d commit 0a193e4
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Image from 'next/image';
import Link from 'next/link';
import { usePathname, useRouter } from 'next/navigation';
import { useEffect } from 'react';

export default function Footer() {
const router = useRouter();
Expand All @@ -15,17 +16,26 @@ export default function Footer() {
{ name: 'Contact', href: '/#contact' },
];

useEffect(() => {
const hash = window.location.hash;
if (hash) {
const id = hash.replace('#', '');
// Wait for the DOM to be ready
setTimeout(() => {
document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' });
}, 100);
}
}, [path]);

const handleNavigation = (href: string) => {
if (href.includes('#')) {
const [page, section] = href.split('#');
const targetPage = page || '/';

if (path === page) {
if (path === targetPage) {
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
router.push(targetPage + '#' + section);
}
} else {
router.push(href);
Expand Down

0 comments on commit 0a193e4

Please sign in to comment.