这个问题有答案,但没有一个解决了我的问题,我尝试了connect-flash,express flash,但没有一个对我有用,我不知道哪里出了错
app.js文件
const express =require('express');
const bodyParser=require('body-parser');
const cookieParser = require('cookie-parser');
const router = require('./routes');
let bb = require( 'express-busboy' );
//const dataroutes = require('./routes');
const path = require('path');
const session = require('express-session');
const LocalStrategy = require('passport-local').Strategy;
const passport = require('passport');
const con=require('./mysql.js');
const MySQLStore = require('express-mysql-session')(session);
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var flash = require('connect-flash');
app.use(cookieParser());
app.use(session({
secret: 'keyboard cat',
resave: false,
store:sessionStore ,
saveUninitialized: true,
cookie: { maxAge: 60000 }
}));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(function(req,res,next){
res.locals.isAuthenticated=req.isAuthenticated();
next();
});
index.js(路由)文件
/* GET login page. */
router.get('/', function(req, res, next) {
//req.flash('notify', 'This is a test notification.');
res.render('index', { messages: req.flash('info') });
});
显示它
<div class="login">
<% if ( messages ) { %>
<p>Message: <%= messages.info %> </p>
<% } %>
我遵循了文档,寻找了已经问过的相关问题,但是没有一个起作用。我在这里遗漏了什么吗?