-
Notifications
You must be signed in to change notification settings - Fork 0
/
Routes.js
34 lines (30 loc) · 986 Bytes
/
Routes.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
import React, { useContext } from "react";
import { Redirect, Route, Switch } from "react-router-dom";
import UserContext from "./context/UserContext";
import Register from "./pages/Register";
import Login from "./pages/Login";
import Home from "./pages/Home";
import MyBooks from "./pages/MyBooks";
const Routes = () => {
const { user } = useContext(UserContext);
return (
<Switch>
<Route path="/" exact>
{user.token ? <Redirect to="/home" /> : <Login />}
</Route>
<Route path="/login" exact>
{user.token ? <Redirect to="/home" /> : <Login />}
</Route>
<Route path="/register" exact>
{user.token ? <Redirect to="/home" /> : <Register />}
</Route>
<Route path="/home" exact>
{user.token ? <Home /> : <Redirect to="/login" />}
</Route>
<Route path="/my-books" exact>
{user.token ? <MyBooks /> : <Redirect to="/login" />}
</Route>
</Switch>
);
};
export default Routes;