a77icu5
a77icu5

Reputation: 131

Express 4.7.2 render views

Apparently in Express 4.7.2 render does not explicit ends the execution, that means:

on Express 4.2

res.render('path/to/view');
res.render('path/to/view');

Render display the first view and ends the execution.

on Express 4.7.2

res.render('path/to/view');
res.render('path/to/view');

Throws 'Can't set headers after they are sent' error, for example:

app.get('/path', function(req, res) {
   if ( someFancyValidation ) {
      res.render('error_view');
   }
   res.render('succes_view');
});

We need an explicit 'return' statement in order to get the desirable result.

Upvotes: 0

Views: 97

Answers (1)

ma08
ma08

Reputation: 3744

It should be

app.get('/path', function(req, res) {
  if ( someFancyValidation ) {
     res.render('error_view');
  }
  else//you missed this
     res.render('succes_view');
});

You can't render twice for a single call.

Upvotes: 1

Related Questions