-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathApp.jsx
More file actions
65 lines (53 loc) · 2.46 KB
/
App.jsx
File metadata and controls
65 lines (53 loc) · 2.46 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
import React, {useEffect} from "react";
import { Routes, Route, Navigate, useNavigate } from "react-router-dom";
import { Dashboard, Auth } from "@/layouts";
import VideoFarmById from "./pages/dashboard/VideoFarms/VideoById";
import VideoLikeList from "./pages/dashboard/VideoFarms/VideoLikeList";
import PostDetail from "./pages/dashboard/post/PostDetail";
import CommentPostbyId from "./pages/dashboard/AdminCommentPost/CommentPostbyId";
import CommentPostbyIdPost from "./pages/dashboard/AdminCommentPost/CommentPostbyIdPost";
import CommentPostByIdUser from "./pages/dashboard/AdminCommentPost/CommentPostByIdUser";
import FarmDetail from "./pages/dashboard/farm/FarmDetail";
import { Farms } from "./pages/dashboard/farm/farms";
import UserDetail from "./pages/dashboard/user/UserDetail";
import VideoById from "./pages/dashboard/VideoFarms/VideoById";
function App() {
const navigate = useNavigate();
useEffect(() => {
const token = localStorage.getItem("token");
if (!token) {
navigate("/auth/sign-in");
}
const handleUnload = () => {
if (performance.getEntriesByType("navigation")[0].type !== "reload") {
localStorage.removeItem("token");
localStorage.removeItem("refreshToken");
localStorage.removeItem("apiBaseUrl");
}
};
window.addEventListener("beforeunload", handleUnload);
return () => {
window.removeEventListener("beforeunload", handleUnload);
}
}, [navigate]);
return (
<Routes>
<Route path="/dashboard/*" element={<Dashboard />}>
<Route path="VideoFarmById/:farmId" element={<VideoFarmById />} />
<Route path="video-like/:videoId" element={<VideoLikeList />} />
<Route path="post/:id" element={<PostDetail />} />
<Route path="CommentPostbyId/:id" element={<CommentPostbyId />} />
<Route path="CommentPostbyIdPost/:postId" element={<CommentPostbyIdPost />} />
<Route path="CommentPostByIdUser/:id" element={<CommentPostByIdUser />} />
<Route path="VideoFarms/VideoById/:id" element={<VideoById />} />
<Route path="users/:id" element={<UserDetail />} />
{/* <Route path="/dashboard/users/:id" element={<UserDetail />} /> */}
</Route>
<Route path="/auth/*" element={<Auth />} />
<Route path="/admin/Farms" element={<Farms />} />
<Route path="/admin/farms/:id" element={<FarmDetail />} />
<Route path="*" element={<Navigate to="/dashboard/home" replace />} />
</Routes>
);
}
export default App;