1

我无法收到快讯。以下是我在路线中调用它们的方式:

middlewareObj.isLoggedIn = function(req, res, next){
    if(req.isAuthenticated()){
        return next();
    }
    req.flash("error", "You must be logged in to do that.");
    res.redirect("/login");
};

这是我的相关 app.js 设置:

var express                 = require("express"),
    app                     = express(),
    bodyParser              = require("body-parser"),
    mongoose                = require("mongoose"),
    passport                = require("passport"),
    flash                   = require("connect-flash");

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

我的模板代码如下所示:

<% if(error && error.length > 1){ %>
    <%console.log(error)%>
    <div class="alert alert-danger" role="alert">
        <%= error %>
    </div>
<% } %>

完全卡住了。有任何想法吗?

4

1 回答 1

1
<% if(error && error.length > 1){ %>

需要是

<% if(error && error.length >0){ %>
于 2019-03-17T00:06:15.620 回答