0

In my Express app, when the admin sucessfully logs in, I want him to be sent to his dashboard page. So in the post function, on success, I redirect to admin/ which takes him to the next function

So I have:

adminRoutes.get('/', function(req, res){
    console.log("/", path.join(__dirname, 'public/admin/index.html'));

    res.sendFile(path.join(__dirname, 'public/admin/index.html'), {}, function (err) {
        if (err) {
          console.log(err);
          res.status(err.status).end();
      }
      else {
          console.log('Sent:');
      }
  });
});

But the problem is, nothing happens in my browser. It just stays on the browser page. It doesn't change to the new page I'm sending.

Why is it not working?

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363

1 Answers1

1

You should do a redirect not sendFile. sendFile is for telling the browser to download a specific file. Try:

res.redirect('public/admin');

Also, make sure this is registered in your routes. The route should then render the HTML.

beautifulcoder
  • 10,832
  • 3
  • 19
  • 29