11import { createBrowserRouter , RouterProvider , Outlet } from "react-router-dom" ;
2+ import { lazy , Suspense } from "react" ;
23import Navbar from "./components/Navbar" ;
34import Footer from "./components/Footer" ;
45import ScrollProgressBar from "./components/ScrollProgressBar" ;
56import { Toaster } from "react-hot-toast" ;
67import ThemeWrapper from "./context/ThemeContext" ;
78
8- import Tracker from "./pages/Tracker/Tracker .tsx" ;
9- import About from "./pages/About/About" ;
10- import Contact from "./pages/Contact/Contact" ;
11- import Contributors from "./pages/Contributors/Contributors" ;
12- import Signup from "./pages/Signup/Signup.tsx" ;
13- import Login from "./pages/Login/Login .tsx" ;
14- import ContributorProfile from "./pages/ContributorProfile/ContributorProfile .tsx" ;
15- import Home from "./pages/Home/Home .tsx" ;
9+ const Home = lazy ( ( ) => import ( "./pages/Home/Home .tsx" ) ) ;
10+ const Tracker = lazy ( ( ) => import ( "./pages/Tracker/Tracker.tsx" ) ) ;
11+ const About = lazy ( ( ) => import ( "./pages/About/About" ) ) ;
12+ const Contact = lazy ( ( ) => import ( "./pages/Contact/Contact" ) ) ;
13+ const Contributors = lazy ( ( ) => import ( "./pages/Contributors/Contributors" ) ) ;
14+ const Signup = lazy ( ( ) => import ( "./pages/Signup/Signup .tsx" ) ) ;
15+ const Login = lazy ( ( ) => import ( "./pages/Login/Login .tsx" ) ) ;
16+ const ContributorProfile = lazy ( ( ) => import ( "./pages/ContributorProfile/ContributorProfile .tsx" ) ) ;
1617
1718function RootLayout ( ) {
1819 return (
@@ -21,7 +22,9 @@ function RootLayout() {
2122 < ScrollProgressBar />
2223 < Navbar />
2324 < main className = "flex-grow bg-gray-50 dark:bg-gray-800 flex justify-center items-center" >
24- < Outlet />
25+ < Suspense fallback = { < div className = "p-6" > Loading…</ div > } >
26+ < Outlet />
27+ </ Suspense >
2528 </ main >
2629 < Footer />
2730 < Toaster
@@ -44,6 +47,7 @@ const router = createBrowserRouter([
4447 {
4548 path : "/" ,
4649 element : < RootLayout /> ,
50+ errorElement : < div className = "p-6" > Something went wrong loading this page.</ div > ,
4751 children : [
4852 { index : true , element : < Home /> } ,
4953 { path : "track" , element : < Tracker /> } ,
@@ -61,7 +65,6 @@ export default function AppRouter() {
6165 return (
6266 < RouterProvider
6367 router = { router }
64- future = { { v7_startTransition : true } as any }
6568 />
6669 ) ;
6770}
0 commit comments