-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
62 lines (57 loc) · 1.72 KB
/
App.tsx
File metadata and controls
62 lines (57 loc) · 1.72 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
import React from 'react';
import { HashRouter as Router, Routes, Route, Navigate } from './context/AuthContext';
import { AuthProvider, useAuth } from './context/AuthContext';
import { Navbar } from './components/Navbar';
import { Footer } from './components/Footer';
import { BackendError } from './components/BackendError';
import { Home } from './pages/Home';
import { Search } from './pages/Search';
import { Login } from './pages/Login';
import { Register } from './pages/Register';
import { Dashboard } from './pages/Dashboard';
import { ServiceDetails } from './pages/ServiceDetails';
// Protected Route Component
const ProtectedRoute = ({ children }: { children?: React.ReactNode }) => {
const { isAuthenticated } = useAuth();
if (!isAuthenticated) {
return <Navigate to="/login" replace />;
}
return <>{children}</>;
};
const AppRoutes = () => {
return (
<div className="flex flex-col min-h-screen">
<BackendError />
<Navbar />
<div className="flex-grow">
<Routes>
<Route path="/" element={<Home />} />
<Route path="/search" element={<Search />} />
<Route path="/service/:id" element={<ServiceDetails />} />
<Route path="/login" element={<Login />} />
<Route path="/register" element={<Register />} />
{/* Protected Routes */}
<Route
path="/dashboard"
element={
<ProtectedRoute>
<Dashboard />
</ProtectedRoute>
}
/>
</Routes>
</div>
<Footer />
</div>
);
};
const App = () => {
return (
<AuthProvider>
<Router>
<AppRoutes />
</Router>
</AuthProvider>
);
};
export default App;