I'm a new user to react.js, trying to make a simple login page that takes the credentials of the user as input but after authentication , I'm not able to redirect into other page programatically. I'm using react.js V16.X and i've tried using
- Redirect
- this.history.props.push()
Help me out with this
class Login extends Component{
static contextTypes={
router: PropTypes.object
};
constructor(){
super()
{
this.state ={
username: '',
password: '',
toDashboard: false,
};
}
this.handleChange = this.handleChange.bind(this);
this.login=this.login.bind(this);
}
handleChange(e) {
this.setState({ [e.target.name]: e.target.value });
}
login(e)
{
//console.log(this.state.username);
// if(this.state.username==="asdf")
// {
// console.log(this.props);
//
this.setState({toDashboard:true})
// }
}
render()
{
console.log(this.state.toDashboard);
if(this.state.toDashboard===true){
return(
// <Router>
// <Redirect to="/login" Component={After}/>
// </Router>
histroy.push("/")
)
console.log("in if statement");
}
return(
<div>
<div>
<input value={this.state.username} type="text" name="username" onChange={this.handleChange}/ >
</div>
<br/>
<div>
<input value={this.state.password} type="password" name="password" onChange={this.handleChange}/>
</div>
<div>
<button type="submit" name="click" onClick={this.login}>button</button>
</div>
</div>
);
}
}
export default Login