-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathApp.js
More file actions
82 lines (77 loc) · 2.45 KB
/
App.js
File metadata and controls
82 lines (77 loc) · 2.45 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
// ## Namaste React Course by Akshay Saini
// Chapter 08 - Let's get Classy
import React from "react";
import ReactDOM from "react-dom/client";
import Header from "./Components/Header";
import Body from "./Components/Body";
import Footer from "./Components/Footer";
import About from "./Components/About";
import Error from "./Components/Error";
import Contact from "./Components/Contact";
import Login from "./Components/Login";
import RestaurantMenu from "./Components/RestaurantMenu";
import Profile from "./Components/ProfileClass";
import { createBrowserRouter, RouterProvider, Outlet } from "react-router-dom"; // for routing our page import createBrowserRouter and RouterProvider for providing router & Outlet for children component for nested routing
/* My Food App structure will look like this,
1) Header
- Logo
- Nav Items(right side)
- Cart
2) Body
- Search bar
- Restaurants List
- Restaurant card
- Image
- Name
- Rating
3) Footer
- Links
- Copyrights
*/
// AppLayout component to render: Header, Outlet(it contain children component like body, About, Restaurant Menu etc) and Footer Component
const AppLayout = () => {
return (
<React.Fragment>
<Header />
<Outlet />
<Footer />
</React.Fragment>
);
};
// call createBrowserRouter for routing different pages
const appRouter = createBrowserRouter([
{
path: "/", // show path for routing
element: <AppLayout />, // show component for particular path
errorElement: <Error />, // show error component for path is different
children: [
// show children component for routing
{
path: "/",
element: <Body />,
},
{
path: "about",
element: <About />,
children: [{ // nested routing
path: "profile",
element: <Profile />,
}]
},
{
path: "contact",
element: <Contact />,
},
{
path: "restaurant/:resId",
element: <RestaurantMenu />,
},
],
},
{
path: "login",
element: <Login />,
},
]);
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<RouterProvider router={appRouter} />); // render RouterProvider and use router as props and pass value appRouter