-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
55 lines (37 loc) · 1.74 KB
/
App.js
File metadata and controls
55 lines (37 loc) · 1.74 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
import React, { useContext } from "react";
import { Routes, Route, Navigate } from "react-router-dom";
import Navbar from "./components/Navbar"; // ✅ Ensure Navbar is imported
import Home from "./pages/Home";
import Categories from "./pages/Categories";
import Products from "./pages/Products";
import SkincareProducts from "./pages/SkincareProducts";
import LifestyleProducts from "./pages/LifestyleProducts"; // ✅ Ensure LifestyleProducts is imported
import Payment from "./pages/Payment";
import FeaturedProducts from "./pages/FeaturedProducts"; // ✅ Import FeaturedProducts
import Login from "./pages/Login";
import Cart from "./pages/Cart"; // ✅ FIXED: Import Cart
import { AuthContext } from "./context/AuthContext";
// ✅ Protected Route (Prevents unauthorized access)
const ProtectedRoute = ({ element }) => {
const { user } = useContext(AuthContext);
return user ? element : <Navigate to="/login" />;
};
const App = () => {
return (
<>
<Navbar /> {/* ✅ Navbar is included */}
<Routes>
<Route path="/" element={<Home />} />
<Route path="/categories" element={<Categories />} />
<Route path="/products" element={<Products />} />
<Route path="/skincare-products" element={<SkincareProducts />} />
<Route path="/lifestyle-products" element={<LifestyleProducts />} /> {/* ✅ Ensure Route is Correct */}
<Route path="/cart" element={<ProtectedRoute element={<Cart />} />} />
<Route path="/payment" element={<ProtectedRoute element={<Payment />} />} />
<Route path="/featured-products" element={<FeaturedProducts />} /> {/* ✅ FeaturedProducts Route */}
<Route path="/login" element={<Login />} />
</Routes>
</>
);
};
export default App;