0

This code is incorrect. Redirect only redirects, I don't think you can pass results through it.

router.post('/form', function(req, res, next){
  var student = new StudentModel({
    firstName: req.body.firstName,
    lastName: req.body.lastName,
  });

  student.save(function (err) {
    if (err) return handleError(err);
    db.collection("studentmodels").find().toArray(function(err, result) {
      if (err) throw err;
        res.redirect('/submitted', { data: result});  -- what can I do here?
    });
  });
});

Is there a way to redirect and include this information?
I would like to use:

res.render('submitted', { data: result})

But I can't change the URL path

k..a..b
  • 61
  • 1
  • 12
Payton Dugas
  • 107
  • 1
  • 2
  • 8
  • Could you edit the question and provide more clarity as to what you are trying to achieve. This will help the community to better help. – k..a..b Jun 15 '21 at 20:29

1 Answers1

0

There are some ways to pass the data to the new route.

you can render the submitted template file by passing data if you don't want to change the URI

If you want the specific URI you can pass the data as query params into your route you can see the example in the below https://stackoverflow.com/a/19038048/6551916

Tharunkumar
  • 170
  • 3
  • 17