-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
41 lines (35 loc) · 977 Bytes
/
App.js
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
import Home from "./pages/Home";
import Login from "./pages/Login";
import Register from "./pages/Register";
import "./style.scss"
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom"
import { useContext } from "react";
import { AuthContext } from "./context/AuthContext";
function App() {
const {currentUser} = useContext(AuthContext)
const ProtectedRoute = ({children}) =>{
if(!currentUser){
return <Navigate to="/login"/>
}
return children
};
return (
<BrowserRouter>
<Routes>
<Route path="/">
<Route
index
element={
<ProtectedRoute>
<Home />
</ProtectedRoute>
}
/>
<Route path="login" element={<Login />} />
<Route path="register" element={<Register />} />
</Route>
</Routes>
</BrowserRouter>
);
}
export default App;