Skip to content

Commit c6599db

Browse files
authored
Merge pull request realstoman#21 from SubhamB2003/add-test
Add lazy loading to routes
2 parents 062e127 + 053f135 commit c6599db

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

public/_redirects

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* /index.html 200

src/App.js

+22-17
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
1-
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
1+
import { AnimatePresence } from 'framer-motion';
2+
import { lazy, Suspense } from 'react';
3+
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
24
import ScrollToTop from './components/ScrollToTop';
35
import AppFooter from './components/shared/AppFooter';
46
import AppHeader from './components/shared/AppHeader';
57
import './css/App.css';
6-
import About from './pages/AboutMe';
7-
import Contact from './pages/Contact.jsx';
8-
import Home from './pages/Home';
9-
import Projects from './pages/Projects';
10-
import ProjectSingle from './pages/ProjectSingle.jsx';
11-
import { AnimatePresence } from 'framer-motion';
128
import UseScrollToTop from './hooks/useScrollToTop';
139

10+
const About = lazy(() => import('./pages/AboutMe'));
11+
const Contact = lazy(() => import('./pages/Contact.jsx'));
12+
const Home = lazy(() => import('./pages/Home'));
13+
const Projects = lazy(() => import('./pages/Projects'));
14+
const ProjectSingle = lazy(() => import('./pages/ProjectSingle.jsx'));
15+
16+
1417
function App() {
1518
return (
1619
<AnimatePresence>
1720
<div className=" bg-secondary-light dark:bg-primary-dark transition duration-300">
1821
<Router>
1922
<ScrollToTop />
2023
<AppHeader />
21-
<Routes>
22-
<Route path="/" element={<Home />} />
23-
<Route path="projects" element={<Projects />} />
24-
<Route
25-
path="projects/single-project"
26-
element={<ProjectSingle />}
27-
/>
24+
<Suspense fallback={""}>
25+
<Routes>
26+
<Route path="/" element={<Home />} />
27+
<Route path="projects" element={<Projects />} />
28+
<Route
29+
path="projects/single-project"
30+
element={<ProjectSingle />}
31+
/>
2832

29-
<Route path="about" element={<About />} />
30-
<Route path="contact" element={<Contact />} />
31-
</Routes>
33+
<Route path="about" element={<About />} />
34+
<Route path="contact" element={<Contact />} />
35+
</Routes>
36+
</Suspense>
3237
<AppFooter />
3338
</Router>
3439
<UseScrollToTop />

0 commit comments

Comments
 (0)