我正在尝试 Sails.js beta 版本 (1.0.0-46),并注意到 Flash 消息无法开箱即用:
req.flash(type, message)
我在尝试使用它时收到TypeError: req.flash is not a function消息。
最佳答案
哎呀...刚刚在升级文档中找到了答案 ( Upgrading to v1.0 )。
The connect-flash middleware has been removed (so req.flash() will no longer be available by default). If you wish to continue using req.flash(), run npm install --save connect-flash in your app folder and add the middleware manually.
运行以下命令:
npm install --save connect-flash
并修改config/http.js文件:
middleware: {
flash : require('connect-flash')(),
order: [
'cookieParser',
'session',
'flash', // <-- add this
// 'bodyParser',
'compress',
'poweredBy',
'router',
'www',
'favicon',
],
关于sails.js - Sails 1.0.0(测试版)中是否存在 Flash 消息 (req.flash)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48939826/