No puedo usar el paquete connect-flash para res.render. Mi objetivo principal es mostrar un mensaje flash en la representación de una vista.
Puedo hacer que funcione con un res.redirect ("ruta") pero no con el código res.render ("ver"). ¿Es por diseño?
Mi código se muestra a continuación
if(err){ // Apparently res.render("register") didn't work with flash. But res.redirect("/register") worked. req.flash("error", err.message); // Error occurs when the user is taken, password is empty etc. return res.redirect("/register"); // Short circut everything. Else the code below this would run as well and that would throw an error }Esta es la sintaxis correcta para usar req.flash con res.render:
req.flash('error', yourErrString); res.render("register.ejs", { message: req.flash('error') });