the app function have a router and i well use them in the components thanks for help ....
function App() {
return (
<Router>
<div className='App'>
<Switch>
<Route exact path='/'>
<Login />
</Route>
<Route path='/SignUp'>
<SignUp />
</Route>
</Switch>
<Route
path='/Student/:id'
exact
render={({ match }) => <Student match={match} />}
/>
<Route
path='/Admin/:id'
exact
render={({ match }) => <Admin match={match} />}
/>
</div>
</Router>
);
}
export default App;
just need to use redirect after the admin decided to click on the logout button without using usehistory.
const Admin = () => {
const logoutfunc = async () => {
let connectToServer = new ConnectToServer();
//let session=await connectToServer.getSession()
connectToServer.logout();
};
const redirect = () => {
return <Redirect to={{ pathname: '/' }} />;
};
return (
<div>
<button
onClick={() => {
logoutfunc();
redirect();
}}
>
logout
</button>
<Cards />
<TableStudent />
<Cohorts />
</div>
);
};
export default Admin;