I am new to react js and trying to implement the auto logout feature in reactjs. However it doesnot seem to work.
I have tried using history.push feature in react to no avail
Here is what I am trying to do:
export class Dashboard extends React.Component {
constructor(props) {
super(props);
this.state = {
email: '',
redirect: false,
};
this.redirectTimeout = null;
}
componentDidMount = () => {
const { history } = this.props;
var search = window.location.search;
var params = new URLSearchParams(search);
var requestid = params.get('q');
this.getService();
this.getspcCode();
this.getLocations();
this.getZone();
**this.redirectTimeout = setTimeout(() => {
history.push('/Login')
}, 5000);**
};
I am trying to use history.push Login to make it work. In my nav bar on the click of a button it works. However auto logout doesnot.
MY Nav:
export default {
top: [
{
name: 'Home',
url: '/home',
icon: 'Home',
},
{
name: 'LogOut',
url: '/Login',
icon: 'User',
},
{
divider: true,
},
],
};
Could somebody please help me in this? How do I do this?
I am not importing anything like browser history from react router dom or anything. Should I be importing anything for it to work?