Passing error message to template through redirect in Express/Node.js

后端 未结 2 1706
梦毁少年i
梦毁少年i 2020-12-30 07:09

In my Node.js application, I have a function (routed by Express) which presents a form to the user:

app.get(\'/register\', function (req, res) {
  res.render         


        
2条回答
  •  一向
    一向 (楼主)
    2020-12-30 07:59

    You need to use flash notifications, and it is built into express.

    You'll add a message like so: req.flash("error", "Invalid form...");

    You'll need a dynamic handler to add the messages to your rendered template, or you can check out the ones TJ has made for express. (express-messages)

提交回复
热议问题