-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRouters.js
More file actions
111 lines (80 loc) · 3.69 KB
/
Routers.js
File metadata and controls
111 lines (80 loc) · 3.69 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import React, { Component } from 'react';
import { Route, Switch, withRouter } from 'react-router-dom';
import './App.css';
import Administration from './components/Administration/Administration';
import Login from './components/Login/Login';
import Registration from './components/Registration/Registration';
import CustomeCode from './components/Appearance/CustomeCode/CustomeCode';
import AddEntrie from './components/ContentTypesPanel/AddEntrie/AddEntrie';
// import Structure from './components/ContentTypesPanel/Structure/Structure';
import LandingPage from './components/LandingPage/LandingPage';
import PrivatRoute from './components/PrivatRoute/PrivatRoute';
import jwtDecode from 'jwt-decode';
import FileUploader from './components/FileUploader/FileUploader';
import Slider from './components/Slider/Slider';
import ExtandedCTView from './components/LandingPage/LayoutComponents/ExtandedCTView';
class Routers extends Component {
constructor(props) {
super(props);
this.state = {
authenticated: false
}
}
static getDerivedStateFromProps(nextProps, prevState) {
if(localStorage.getItem('token')) {
const tokenStr = jwtDecode(localStorage.getItem('token'));
if(tokenStr) {
return { authenticated: true };
} else {
return { authenticated: false };
}
}
return null;
}
handleLoginSucess(loginData) {
this.setState({authenticated: loginData.isAuthenticated});
this.props.history.push("/Administration");
}
render() {
const login = ()=> (
<Login
history={this.props.history}
handleLoginSuccess={this.handleLoginSucess.bind(this)} />)
console.log(this.state.authenticated);
return (
<Switch>
<Route exact path="/login" component={login} />
<Route exact path="/registration" component={Registration} />
<Route exact path="/" component={LandingPage} />
<Route exact path="/FileUploader" component={FileUploader} />
<Route exact path="/slider" component={Slider} />
<Route path="/ContentType/entries/:entrieId" component={ExtandedCTView} />
<PrivatRoute
authenticated={this.state.authenticated}
exact path="/Administration/" component={Administration} />
<PrivatRoute
authenticated={this.state.authenticated}
path="/AddEntrie" component={AddEntrie} />
<PrivatRoute
authenticated={this.state.authenticated}
exact path="/CustomeCode/" component={CustomeCode} />
<PrivatRoute
authenticated={this.state.authenticated}
path="/Administration/main/:activeLink" component={Administration} />
<PrivatRoute
authenticated={this.state.authenticated}
path="/Administration/Structure/:id" component={Administration} />
<PrivatRoute
authenticated={this.state.authenticated}
path="/Administration/ContentType/:id" component={Administration} />
<PrivatRoute
authenticated={this.state.authenticated}
path="/Administration/Categories/:id" component={Administration} />
<PrivatRoute
authenticated={this.state.authenticated}
path="/Administration/view/:id" component={Administration} />
</Switch>
);
}
}
export default withRouter(Routers);