-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: routes and implement lazy loading
- Loading branch information
Showing
2 changed files
with
18 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; | ||
import { Suspense, lazy } from 'react'; | ||
import Navbar from './components/Navbar'; | ||
import Footer from './components/Footer'; | ||
|
||
import Home from './pages/Home'; | ||
import TopPicks from './pages/TopPicks'; | ||
import ArtDescription from './pages/ArtDescription'; | ||
import ErrorPage from './pages/Error'; | ||
// Lazy loading of route components | ||
const Home = lazy(() => import('./pages/Home')); | ||
const TopPicks = lazy(() => import('./pages/TopPicks')); | ||
const ArtDescription = lazy(() => import('./pages/ArtDescription')); | ||
const ErrorPage = lazy(() => import('./pages/Error')); | ||
|
||
function App() { | ||
return ( | ||
<div className="flex flex-col justify-start items-start min-h-screen bg-gray-100"> | ||
<Router> | ||
<Router basename="/artistry-hub/"> | ||
<Navbar /> | ||
|
||
{/* Route Definitions */} | ||
<Routes> | ||
<Route exact path="/artistry-hub/" element={<Home />} /> | ||
<Route exact path="/artistry-hub/top-picks" element={<TopPicks />} /> | ||
<Route path="/artistry-hub/art/:id" element={<ArtDescription />} /> | ||
|
||
{/* Fallback Error Page for Unmatched Routes */} | ||
<Route path="*" element={<ErrorPage />} /> | ||
</Routes> | ||
{/* Suspense fallback during lazy loading */} | ||
<Suspense fallback={<div>Loading...</div>}> | ||
<Routes> | ||
<Route path="/" element={<Home />} /> | ||
<Route path="/top-picks" element={<TopPicks />} /> | ||
<Route path="/art/:id" element={<ArtDescription />} /> | ||
<Route path="*" element={<ErrorPage />} /> | ||
</Routes> | ||
</Suspense> | ||
</Router> | ||
|
||
{/* Footer */} | ||
<Footer /> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters