Node connect-flash not working on redirect

18 Views Asked by At

going through /temp gives flash message enter image description here

but whenever i try to use functions from listRouter flash is not working

const flash=require("connect-flash");
const session = require('express-session');

app.use(session({secret:"secretcode", resave : false, saveUninitialized:true}));
app.use(flash());

app.use((req,res,next)=>{
    res.locals.successMsg=req.flash("success");
    res.locals.errorMsg=req.flash("error");
    next();
})

app.get("/temp",(req,res)=>{
    req.flash("error","Error");
    req.flash("success","Success");
    console.log(res.locals);
    res.redirect("/listings");
})

app.use("/listings/:id/review",reviewRouter);
app.use("/listings",listRouter);
0

There are 0 best solutions below