[英]Understanding req.flash()
I am still confusing about using req.flash in nodejs.我仍然对在 nodejs 中使用 req.flash 感到困惑。
I have .catch like..我有.catch 喜欢..
Login function登录功能
.catch(function(e){
req.flash('errors', 'error here')
res.redirect('/')
})
So this is I make a custom request object with property flash?所以这是我创建一个带有属性 flash 的自定义请求对象?
And because I'm using redirect, now the response object will send the request with custom request to the '/' route?并且因为我正在使用重定向,现在响应对象会将带有自定义请求的请求发送到“/”路由?
I believe you are using req-flash .我相信您正在使用req-flash 。
If you use req.flash()
in the controller of your '/' endpoint, you'll get the following object:如果您在“/”端点的控制器中使用req.flash()
,您将获得以下对象:
{
errors: 'error here',
}
You can then do whatever you want from this point.从这一点开始,你可以做任何你想做的事情。
A common case of usage is to use this to display messages conditionaly.一个常见的用法是使用它来有条件地显示消息。 For instance, you can display an alert if req.flash().errors
is defined.例如,如果定义了req.flash().errors
,您可以显示警报。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.