-
Notifications
You must be signed in to change notification settings - Fork 274
Expand file tree
/
Copy pathApp.js
More file actions
44 lines (39 loc) · 1.3 KB
/
App.js
File metadata and controls
44 lines (39 loc) · 1.3 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
import './App.css';
import { Route, Routes, useLocation } from "react-router-dom";
import Header from './componets/Header';
import React, { useEffect } from 'react';
import Login from './componets/Login';
import Blogs from './componets/Blogs';
import UserBlogs from './componets/UserBlogs';
import AddBlogs from './componets/AddBlogs';
import BlogDetail from './componets/BlogDetail';
import { useDispatch } from 'react-redux';
import { authActions } from './store';
function App() {
const dispatch = useDispatch();
const location = useLocation();
useEffect(() => {
const userId = localStorage.getItem("userId");
if (userId) {
dispatch(authActions.login());
}
}, [dispatch]);
// Don't show header on login page
const hideHeaderRoutes = ['/login'];
const shouldHideHeader = hideHeaderRoutes.includes(location.pathname);
return (
<React.Fragment>
{!shouldHideHeader && <Header />}
<main>
<Routes>
<Route path="/login" element={<Login />} />
<Route path="/blogs" element={<Blogs />} />
<Route path="/myBlogs" element={<UserBlogs />} />
<Route path="/myBlogs/:id" element={<BlogDetail />} />
<Route path="/blogs/add" element={<AddBlogs />} />
</Routes>
</main>
</React.Fragment>
);
}
export default App;