diff --git a/src/App.jsx b/src/App.jsx index 0569b06..d47fc2a 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -7,6 +7,7 @@ import Hero from './components/Hero'; import About from './components/About'; import Projects from './components/Projects'; import Contact from './components/Contact'; +import NotFound from './components/NotFound'; import Footer from './components/Footer'; import styles from './App.module.scss'; @@ -27,18 +28,15 @@ export default function App() { const [displayedSection, setDisplayedSection] = useState(activeSection); const timerRef = useRef(null); + const path = location.pathname.substring(1) || 'home'; + const notFound = !Object.keys(SECTIONS).includes(path); + // Sync URL path with activeSection useEffect(() => { - const path = location.pathname.substring(1) || 'home'; - if (Object.keys(SECTIONS).includes(path)) { - if (path !== activeSection) { - setActiveSection(path); - } - } else { - // Invalid path, redirect to home - navigate('/'); + if (!notFound && path !== activeSection) { + setActiveSection(path); } - }, [location.pathname, activeSection, setActiveSection, navigate]); + }, [location.pathname, activeSection, setActiveSection, navigate, path, notFound]); useEffect(() => { if (theme === 'light') { @@ -59,6 +57,18 @@ export default function App() { const isExiting = activeSection !== displayedSection; const Section = SECTIONS[displayedSection] ?? Hero; + if (notFound) { + return ( + <> + +
+ +
+