express4.x connect-flash出错
发布于 4个月前 作者 cjingzm 777 次浏览 来自 问答

var flash = require(‘connect-flash’); app.use(flash());

引用时出现下面问题。新手求指点。 req.flash() requires sessions

undefined

Error: req.flash() requires sessions at Error (<anonymous>) at IncomingMessage._flash [as flash] (D:\MyDevelop\express_test\blogs\node_modules\connect-flash\lib\flash.js:60:41) at D:\MyDevelop\express_test\blogs\routes\index.js:23:9 at Layer.handle [as handle_request] (D:\MyDevelop\express_test\blogs\node_modules\express\lib\router\layer.js:76:5) at next (D:\MyDevelop\express_test\blogs\node_modules\express\lib\router\route.js:100:13) at Route.dispatch (D:\MyDevelop\express_test\blogs\node_modules\express\lib\router\route.js:81:3) at Layer.handle [as handle_request] (D:\MyDevelop\express_test\blogs\node_modules\express\lib\router\layer.js:76:5) at D:\MyDevelop\express_test\blogs\node_modules\express\lib\router\index.js:234:24 at Function.proto.process_params (D:\MyDevelop\express_test\blogs\node_modules\express\lib\router\index.js:312:12) at D:\MyDevelop\express_test\blogs\node_modules\express\lib\router\index.js:228:12

1 回复

在 flash 中间件之前挂个 session 中间件:https://github.com/expressjs/session

回到顶部