From f64680578d907e5afff58962d8be7cb9e37fa099 Mon Sep 17 00:00:00 2001 From: Park Dahyeon Date: Sat, 15 Nov 2025 14:46:23 +0000 Subject: [PATCH] refactor: Migrate App.tsx to use React Router --- src/App.tsx | 90 ++++++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index f80167f..4a51001 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,13 +2,13 @@ import { Header } from './components/Header'; import { HomePage } from './components/HomePage'; import { DocumentationPage } from './components/DocumentationPage'; import { useState } from 'react'; +import { Routes, Route, useParams, useNavigate } from 'react-router-dom'; -export default function App() { - const [currentPage, setCurrentPage] = useState<'home' | 'documentation'>('home'); +function DocumentationPageWrapper() { + const { taxonomyId, articleSlug } = useParams<{ taxonomyId?: string; articleSlug?: string }>(); const [isSidebarOpen, setIsSidebarOpen] = useState(false); const [theme, setTheme] = useState<'light' | 'dark'>('light'); - const [currentTaxonomyId, setCurrentTaxonomyId] = useState(null); - const [currentArticleSlug, setCurrentArticleSlug] = useState(null); + const navigate = useNavigate(); const toggleSidebar = () => { setIsSidebarOpen(!isSidebarOpen); @@ -18,27 +18,12 @@ export default function App() { setTheme(theme === 'light' ? 'dark' : 'light'); }; - const navigateToHome = () => { - setCurrentPage('home'); - setIsSidebarOpen(false); - setCurrentTaxonomyId(null); - setCurrentArticleSlug(null); - }; - - const navigateToDocumentation = () => { - setCurrentPage('documentation'); - setIsSidebarOpen(false); - }; - - const handleTaxonomyClick = (taxonomyId: string) => { - setCurrentPage('documentation'); - setCurrentTaxonomyId(taxonomyId); - setCurrentArticleSlug(null); - setIsSidebarOpen(false); - }; - const handleArticleClick = (slug: string) => { - setCurrentArticleSlug(slug); + if (taxonomyId) { + navigate(`/contents/${taxonomyId}/${slug}`); + } else { + navigate(`/contents/article/${slug}`); + } }; return ( @@ -47,26 +32,17 @@ export default function App() { toggleSidebar={toggleSidebar} theme={theme} toggleTheme={toggleTheme} - navigateToHome={navigateToHome} - navigateToDocumentation={navigateToDocumentation} - onTaxonomyClick={handleTaxonomyClick} /> - - {currentPage === 'home' ? ( - - ) : ( - - )} - + {/* Mobile overlay */} - {isSidebarOpen && currentPage === 'documentation' && ( + {isSidebarOpen && (
); } + +function HomePageWrapper() { + const [theme, setTheme] = useState<'light' | 'dark'>('light'); + + const toggleTheme = () => { + setTheme(theme === 'light' ? 'dark' : 'light'); + }; + + return ( +
+
{}} + theme={theme} + toggleTheme={toggleTheme} + /> + +
+ ); +} + +export default function App() { + return ( + + } /> + } /> + } /> + } /> + + ); +}