连接闪存消息不适用于res.render(“SomeView”)

时间:2017-04-17 06:49:34

标签: node.js express npm connect-flash

我无法使用connect-flash包进行res.render。 我的主要目的是在渲染视图时显示flash消息。

我能够使用res.redirect(“route”)但不能使用res.render(“view”)代码。这是设计吗?

我的代码如下所示

if(err){
      // Apparently res.render("register") didn't work with flash. But res.redirect("/register") worked.
        req.flash("error", err.message);   // Error occurs when the user is taken, password is empty etc.
        return res.redirect("/register");  // Short circut everything. Else the code below this would run as well and that would throw an error
    }

1 个答案:

答案 0 :(得分:2)

这是使用req.flash和res.render的正确语法:

select year(date), month(date), 
       sum(case when status = 'open' then 1 else 0 end) as open_count,
       sum(case when status = 'closed' then 1 else 0 end) as closed_count,
       count(*) as total_count
from your_table
group by year(date), month(date)