-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
26 lines (23 loc) · 789 Bytes
/
App.js
File metadata and controls
26 lines (23 loc) · 789 Bytes
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
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import Login from './pages/Login';
import Home from './pages/Home';
import AdminDashboard from './pages/AdminHome';
import { useState } from 'react';
import './index.css';
function App() {
const [auth, setAuth] = useState({ isLoggedIn: false, role: null });
return (
<Router>
<Routes>
<Route path="/" element={<Login setAuth={setAuth} />} />
<Route path="/home" element={
auth.isLoggedIn && auth.role === 'user' ? <Home /> : <Navigate to="/" />
} />
<Route path="/admin" element={
auth.isLoggedIn && auth.role === 'admin' ? <AdminDashboard /> : <Navigate to="/" />
} />
</Routes>
</Router>
);
}
export default App;