2021-04-02 17:22:34 +05:00
|
|
|
import './styles/App.less'
|
|
|
|
import React /*, { useContext, createContext, useState }*/ from "react"
|
|
|
|
import {
|
|
|
|
BrowserRouter as Router,
|
|
|
|
Switch,
|
|
|
|
Route,
|
|
|
|
Redirect
|
|
|
|
} from "react-router-dom"
|
|
|
|
import Login from './pages/Login'
|
|
|
|
import Main from './pages/Main'
|
|
|
|
import {OpenAPI} from './services/api'
|
2021-03-31 15:54:02 +05:00
|
|
|
|
2021-04-02 17:22:34 +05:00
|
|
|
OpenAPI.BASE = 'http://localhost:3000'
|
|
|
|
OpenAPI.TOKEN = localStorage['token']
|
|
|
|
|
|
|
|
function PrivateRoute({ children, ...rest }) {
|
|
|
|
let token = localStorage['token']
|
2021-03-31 15:54:02 +05:00
|
|
|
return (
|
2021-04-02 17:22:34 +05:00
|
|
|
<Route
|
|
|
|
{...rest}
|
|
|
|
render={({ location }) =>
|
|
|
|
token
|
|
|
|
? (children)
|
|
|
|
: (<Redirect to={{pathname: "/login",state: { from: location }}}/>)
|
|
|
|
}
|
|
|
|
/>
|
2021-03-31 15:54:02 +05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-02 17:22:34 +05:00
|
|
|
export default function App() {
|
|
|
|
return (
|
|
|
|
<Router>
|
|
|
|
<Switch>
|
|
|
|
<Route path="/login">
|
|
|
|
<Login />
|
|
|
|
</Route>
|
|
|
|
<PrivateRoute path="/">
|
|
|
|
<Main />
|
|
|
|
</PrivateRoute>
|
|
|
|
</Switch>
|
|
|
|
</Router>
|
|
|
|
)
|
|
|
|
}
|