1

I want to put variables inside res redirect inside the post route and then get that variable in get route. I don't know how to do it. Thank you.

router.post("/message", function(req, res) {
 var email = req.body.email;
 res.redirect("/passingemail/<%= email %>");  // I try to put the variable email like this but it doesn't work
});

//my goal is I want to get the value here 
router.get("/paddingemail/:email", function (req, res){
});
wzwd
  • 169
  • 2
  • 10

3 Answers3

0

See this answer.

You can also just go res.redirect("/passingemail/" + email);

Jeff Breadner
  • 1,366
  • 9
  • 19
0
res.redirect("/passingemail/"+email); 

or with ES6

res.redirect(`/passingemail/${email}`); 
Cristian Tr
  • 716
  • 1
  • 7
  • 25
  • Thank you it works. I don't know what was wrong with me. I have used this kind of method may time. I think my mind was off. – wzwd May 15 '18 at 02:51
0

Try it

router.post("/message", function(req, res) {
    var email = req.body.email;
    res.redirect("/passingemail/" + email);  
});
Roy lin
  • 66
  • 4