title: Why res.redirect('/') doesn't work?
body: <p>I'm implementing a simple login/logout scenario using Express framework on Node.js. For the login I have no problems: on clicking "Login", after providing the correct username and password, the user is correctly redirected to the clientPage:</p>
  
  <pre><code>//POST route for logging in
  router.post('/login', function (req, res, next) {
  if (req.body.logusername &amp;&amp; req.body.logpassword) {
  
      User.authenticate(req.body.logusername, req.body.logpassword, function (error, user) {
        if (error || !user) {
          var err = new Error('Wrong email or password.');
          err.status = 401;
          return next(err);
        } else {
          req.session.userId = user._id;
          return res.redirect('/clientPage');
        }
      });
    } else {
      var err = new Error('All fields required.');
      err.status = 400;
      return next(err);
    }
  })
  
  // GET route after registering
  router.get('/clientPage', function (req, res, next) {
    User.findById(req.session.userId)
      .exec(function (error, user) {
        if (error) {
          return next(error);
        } else {
          if (user === null) {
            var err = new Error('Not authorized! Go back!');
            err.status = 400;
            return next(err);
          } else {
            return res.sendFile(path.join(__dirname + '/../views/clientPage.html'));
          }
        }
      });
  });
  </code></pre>
  
  <p>The behaviour changes when logging out, even though the scenario is not that different: clicking on the "Log out" button in the client page, a "logout()" function is called, which makes an AJAX GET request to "/logout", handled by my routes script:</p>
  
  <pre><code>function logout(){
      $.ajax({
          type: "GET",
          url: '/logout',
          async: true,
      })
  
  }
  
  // GET for logout
  router.get('/logout', function (req, res, next) {
    if (req.session) {
      // delete session object
      req.session.destroy(function (err) {
        if (err) {
          return next(err);
        } else {
          return res.redirect('/');
        }
      });
    }
  });
  </code></pre>
  
  <p>In the Network tab of my browser I see that the first request gets a "200 OK" response and successfully redirects the client to the given page, while the logout request results in "304 Not Modified" answer, containing in the response the page I want (the root, i.e. my homepage), but does not redirect the current page to the new one.</p>