title: how to redirect to a page after successful login in ReactJS?
body: <p>How to redirect to homepage after <code>successful login</code> in ReactJS? and also i want to show <code>error message</code> whenever user enter wrong credential.<br/>
  I tried something like below, but it not redirect to <code>homepage</code> whenever user hit their right credential. and also not showing <code>login failed</code> prompt whenever user hit wrong credential.<br/><br/>
  It would be great if anybody could help me out what i am trying to solve is.</p>
  
  <p><a href="https://i.stack.imgur.com/FgDmd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FgDmd.png" alt="enter image description here"></a></p>
  
  <p>./src/Login.js</p>
  
  <pre><code>import React, {Component} from "react";
  import {Form} from 'antd';
  
  
  export default class App  extends Component{
  
  
    constructor(props) {
          super(props);
          this.state ={
              username: "",
              password: "",
          }
          this.onFormSubmit = this.onFormSubmit.bind(this)
      }
  
      onFormSubmit(values){
        console.log(values);
  
        const formData = new FormData();
        formData.append("username", values.username);
        formData.append("password", values.password);
  
          const options = {
              method: 'POST',
              body: formData
          };
  
         fetch('http://localhost:8000/api/login', options).then(() =&gt; {
            this.props.history.push('/home')
          }).catch((error) =&gt; {
          alert('Login Failed!')
          })
  
  
      };
  
  
   render(){
      return(
  
        &lt;div&gt;
                              &lt;Form onFinish={this.onFormSubmit}&gt;
                                  &lt;div class="col-md-12 form-group p_star"&gt;
                                      &lt;Form.Item name="username"&gt;
                                        &lt;input type="text" class="form-control" placeholder="Username"/&gt;
                                      &lt;/Form.Item&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-md-12 form-group p_star"&gt;
                                    &lt;Form.Item name="password"&gt;
                                      &lt;input type="password" class="form-control"
                                          placeholder="Password"/&gt;
                                     &lt;/Form.Item&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-md-12 form-group"&gt;
                                      &lt;button type="submit" value="submit" class="btn_3"&gt;
                                          log in
                                      &lt;/button&gt;
                                  &lt;/div&gt;
                              &lt;/Form&gt;
  
       &lt;/div&gt;
  
  </code></pre>