Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/components/navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Link from 'next/link';
import React, { useState } from 'react';
import { useRouter, usePathname } from 'next/navigation';
import styles from './style.module.css';
import Logo from '../../../public/Logo';

Expand All @@ -16,6 +17,8 @@ const NAV_LINKS = [

const Navbar: React.FC = () => {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const router = useRouter();
const pathname = usePathname();

// Inject smooth scroll CSS once
React.useEffect(() => {
Expand All @@ -31,15 +34,19 @@ const Navbar: React.FC = () => {
const handleNavClick = (e: React.MouseEvent<HTMLElement>, href: string) => {
if (href.startsWith('/#')) {
e.preventDefault();
const id = href.split('#')[1];
const el = document.getElementById(id);
if (el) {
el.scrollIntoView({ behavior: 'smooth' });
}
// Optionally close menu on mobile
setIsMenuOpen(false);
// Update URL hash without page reload
window.history.pushState(null, '', href);
if (pathname === '/') {
// Already on home, scroll smoothly
const id = href.split('#')[1];
const el = document.getElementById(id);
if (el) {
el.scrollIntoView({ behavior: 'smooth' });
}
window.history.pushState(null, '', href);
} else {
// Not on home, navigate to home with hash
router.push(href);
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/homepage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const HomePage: NextPage<{ past_events: EventsArray; future_events: EventsArray
<section id="team">
<Team />
</section>
<section id="contact">{/* Add your Contact component or content here */}</section>
<section id="contact">{}</section>
</main>
);
};
Expand Down