使用res.render时,使用flash-connect不会闪烁任何消息

时间:2018-08-07 09:17:55

标签: node.js express

当我在res.redirect()之前使用Flash时,它可以正常工作,但是当我在res.render()之前使用Flash时。它对我不起作用,没有消息闪烁

router.post("/register",function(req,res){
   var username=new User({username:req.body.username});
    User.register(username,req.body.password,function(err,user)
    {
        if(err){

        req.flash("error","user already signed in");
        return res.render("register",);
        }

这是我的app.js配置

app.use(function(req,res,next){
    res.locals.currentUser=req.user;
    res.locals.error=req.flash("error")
    res.locals.success=req.flash("success")
    next();
})

0 个答案:

没有答案