router.js
1.58 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
import React from 'react'
import { HashRouter, Route, Switch, Redirect } from 'react-router-dom'
import App from './App'
// import axios from '@src/axios'
// import { API_ROLE_MANAGE, API_MENU_MANAGE } from '@src/Api'
import Home from './admin'
import AuthRoute from '@src/components/AuthRoute/authroute'
// import Storage from '@src/utils/localStorage'
import Login from './pages/Login/login'
import Routers from './router/routerMap'
export default class IRouter extends React.Component {
constructor(props) {
super(props)
this.state = {
hasError: false
}
}
componentDidCatch(err, info) {
console.log(err, info);
this.setState({
hasError: true
})
}
state = {
curRole: []
}
componentDidMount() {
}
render() {
const { curRole } = this.state
return this.state.hasError ? <HashRouter>
<Redirect to="/home" />
</HashRouter> : (
<HashRouter>
<App>
<Switch>
<Route exact path='/login' component={Login} />
<Route path='/' render={() =>
<Home>
<AuthRoute >
<Switch>
{
Routers.map((item, index) => {
return <Route key={index} path={item.path} exact component={item.component} />
})
}
<Redirect to="/home" />
</Switch>
</AuthRoute >
</Home>
} />
</Switch>
</App>
</HashRouter>
)
}
}