如何将变量放在节点js中的双引号内

时间:2018-05-14 22:30:52

标签: javascript node.js express

我想将变量放在res路由中的res重定向中,然后在get路径中获取该变量。我不知道该怎么做。谢谢。

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){
});

3 个答案:

答案 0 :(得分:0)

请参阅this answer

你也可以去res.redirect("/passingemail/" + email);

答案 1 :(得分:0)

res.redirect("/passingemail/"+email); 

或与ES6

res.redirect(`/passingemail/${email}`); 

答案 2 :(得分:0)

试试吧

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