我根据connect-flash在GitHub上的地址关于Express3.x部分的提示,书写代码如下,并且我也 npm install connect-flash安装了相关module,然后我在相关的jade模版中做了以下判断: if(typeof flash == ‘undefined’) p nothing 最后,我通过/flash访问该页面,最后显示出nothing,即jade模版中没有得到flash! 为什么呢?是因为Connect-flash在最新的Express版本中不可用了么?
var flash = require(‘connect-flash’); var app = express();
app.configure(function() { app.use(express.cookieParser(‘keyboard cat’)); app.use(express.session({ cookie: { maxAge: 60000 }})); app.use(flash()); });
app.get(’/flash’, function(req, res){ // Set a flash message by passing the key, followed by the value, to req.flash(). req.flash(‘info’, ‘Flash is back!’) res.redirect(’/’); });
app.get(’/’, function(req, res){ // Get an array of flash messages by passing the key to req.flash() res.render(‘index’, { messages: req.flash(‘info’) }); });