title: Page Redirect not Working on Node Js and React JS on Simple Login Using Session
body: <p>I am working on a simple login form using React and NodeJs with connected to Mysql DB. The problem is redirect is not working. I am adding redirect method and API in server.js and fetch method in loginpage.js as view below:</p>
  
  <pre><code>// API in server.js
  /sales login
  app.post('/login', jsonParser, (req, res) =&gt; { //jsonParser,
      let username = req.body.username;
    let password = req.body.password;
    console.log("req: ",req.body);
      if (username &amp;&amp; password) {
          dbConn.query(`SELECT * FROM user_tbl WHERE username = ? AND password = ?`, [username, password], (err, results, fields) =&gt; {
              if (results.length &gt; 0) {
                  req.session.loggedin = true;
                  req.session.username = username;
          res.redirect('/home');
          console.log(results)
          console.log("req: ", req.body);
              } else {
                  res.send('Incorrect Username and/or Password!');
              }           
              res.end();
          });
      } else {
          res.send('Please enter Username and Password!');
          res.end();
      }
  });
  
  app.get('/home', (req, res) =&gt; {
      if (req.session.loggedin) {
          res.send('Welcome back, ' + req.session.username + '!');
      } else {
          res.send('Please login to view this page!');
      }
      res.end();
  });
  
  </code></pre>
  
  <p>in loginpage.js, the code looks like :</p>
  
  <pre><code>async SubmitLogin(event){
    event.preventDefault();
    console.log(this.state)
    await fetch(`http://localhost:4000/login`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
        },
        body: JSON.stringify(this.state)
    })
    .then ((response) =&gt; {
      return response.json();
    })
    .then((result) =&gt; {
      console.log(result);
      if (result.Status === 'Invalid')
        alert('Invalid User');
        else
          this.props.history.push({ Home });
          alert('Login Sucessfull');
    })
    .then ((body) =&gt; {
      console.log(body);
    })
    .catch((err) =&gt; {
      return console.log();
    })
  
    alert('Test Submit Login')
  }
  
  </code></pre>
  
  <p>I already tried the connection using postman, and there is no error. And I also tried sending username and password from loginpage.js is also no problem. The result displayed in my terminal:</p>
  
  <p><a href="https://i.stack.imgur.com/M6lZf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M6lZf.png" alt="enter image description here"></a></p>
  
  <p>Hopefully, I can get answer </p>