I am using axios to get data and login but after login i need to redirect to dashboard component and prevent going back and block entering without login. Currently using window.location.href method but i need in react method.
My login Function is:
getLoginDetails(){
var input = document.getElementById("userInput").value;
var pass = document.getElementById("userPassword").value;
axios.post(' http:api here', {
email:input,
pin: pass
})
.then(function (response) {
var status = response.data.status;
if(status === 'success'){
window.location.href="/dashboard";
}else{
alert("Invalid Userid or Password");
}
})
.catch(function (error) {
console.log(error);
});
}
My button is :
<Button
className="login-button"
color={"#36b0ff"}
variant="primary"
onClick={this.getLoginDetails}
>
Login
</Button>
Kindly help me out.Redirect Tag and props are shoeing error.