router.js 1.58 KB
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>
      )
  }
}