-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
84 lines (81 loc) · 2.21 KB
/
App.js
File metadata and controls
84 lines (81 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React, { lazy, Suspense } from "react";
import ReactDOM from "react-dom/client";
import Body from "./src/components/Body";
import Header from "./src/components/Header";
import Footer from "./src/components/Footer";
import Cart from "./src/components/Cart";
import Error from "./src/components/Error";
import { createBrowserRouter, RouterProvider, Outlet } from "react-router-dom";
import RestaurantMenu from "./src/components/RestaurantMenu";
import { Shimmer } from "./src/components/Shimmer";
import { Provider } from "react-redux";
import store from "./src/utils/store";
// import Profile from "./src/components/Profile";
// import About from "./src/components/About";
// import ContactUs from "./src/components/ContactUs";
//Lazy Loading
//Chunking
//Dynamic Import
//on demand Loading / Code Splitting
const Profile = lazy(() => import("./src/components/Profile"));
const ContactUs = lazy(() => import("./src/components/ContactUs"));
const About = lazy(() => import("./src/components/About"));
const AppLayout = () => {
return (
<Provider store={store}>
<Header />
{/* All the children will go into the outlet according to the routes */}
<Outlet />
<Footer />
</Provider>
);
};
const appRouter = createBrowserRouter([
{
path: "/",
element: <AppLayout />,
errorElement: <Error />,
children: [
{
path: "/",
element: <Body />,
},
{
path: "/about",
element: (
<Suspense fallback={<Shimmer />}>
<About/>
</Suspense>
),
children: [
{
path: "profile",
element: (
<Suspense fallback={<Shimmer />}>
<Profile />
</Suspense>
),
},
],
},
{
path: "/contactUs",
element: (
<Suspense fallback={<Shimmer/>}>
<ContactUs />
</Suspense>
),
},
{
path: "/cart",
element: <Cart />,
},
{
path: "/restaurant/:id",
element: <RestaurantMenu />,
},
],
},
]);
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<RouterProvider router={appRouter} />);