Move <Router> to index.js, go home on log out
This commit is contained in:
parent
78f67e845b
commit
9719867ebd
|
@ -1,5 +1,5 @@
|
||||||
import React, { useState, useEffect, useReducer } from 'react';
|
import React, { useState, useEffect, useReducer, useContext } from 'react';
|
||||||
import { BrowserRouter as Router, Switch, Route, Link, useParams } from 'react-router-dom';
|
import { BrowserRouter as Router, Switch, Route, Link, useParams, useHistory } from 'react-router-dom';
|
||||||
import './light.css'; import { Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
|
import './light.css'; import { Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
|
||||||
import { requester } from './utils.js';
|
import { requester } from './utils.js';
|
||||||
import { Home } from './Home.js';
|
import { Home } from './Home.js';
|
||||||
|
@ -18,6 +18,7 @@ function App() {
|
||||||
const [user, setUser] = useState(JSON.parse(localStorage.getItem('user', 'false')));
|
const [user, setUser] = useState(JSON.parse(localStorage.getItem('user', 'false')));
|
||||||
const [refreshCount, refreshUser] = useReducer(x => x + 1, 0);
|
const [refreshCount, refreshUser] = useReducer(x => x + 1, 0);
|
||||||
const [yousure, setYousure] = useState(false);
|
const [yousure, setYousure] = useState(false);
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
function setTokenCache(x) {
|
function setTokenCache(x) {
|
||||||
setToken(x);
|
setToken(x);
|
||||||
|
@ -45,13 +46,14 @@ function App() {
|
||||||
setTokenCache('');
|
setTokenCache('');
|
||||||
setUserCache(false);
|
setUserCache(false);
|
||||||
setYousure(false);
|
setYousure(false);
|
||||||
|
history.push('/');
|
||||||
} else {
|
} else {
|
||||||
setYousure(true);
|
setYousure(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Router>
|
<div>
|
||||||
<div className='content-wrap'>
|
<div className='content-wrap'>
|
||||||
<div className='content-wrap-inside'>
|
<div className='content-wrap-inside'>
|
||||||
|
|
||||||
|
@ -119,8 +121,6 @@ function App() {
|
||||||
content={yousure ? 'You Sure?' : 'Log Out'}
|
content={yousure ? 'You Sure?' : 'Log Out'}
|
||||||
onClick={logout}
|
onClick={logout}
|
||||||
icon='cancel'
|
icon='cancel'
|
||||||
as={Link}
|
|
||||||
to='/'
|
|
||||||
/>
|
/>
|
||||||
<Menu.Item fitted content='' />
|
<Menu.Item fitted content='' />
|
||||||
</Menu.Menu>}
|
</Menu.Menu>}
|
||||||
|
@ -189,7 +189,7 @@ function App() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Footer />
|
<Footer />
|
||||||
</Router>
|
</div>
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
import { BrowserRouter as Router } from 'react-router-dom';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
//import * as serviceWorker from './serviceWorker';
|
//import * as serviceWorker from './serviceWorker';
|
||||||
|
|
||||||
ReactDOM.render(<App />, document.getElementById('root'));
|
ReactDOM.render(<Router><App /></Router>, document.getElementById('root'));
|
||||||
|
|
||||||
// If you want your app to work offline and load faster, you can change
|
// If you want your app to work offline and load faster, you can change
|
||||||
// unregister() to register() below. Note this comes with some pitfalls.
|
// unregister() to register() below. Note this comes with some pitfalls.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user