admin管理员组文章数量:1394774
I am redirecting to a page using
res.redirect('/pageOne');
so after the redirect i want call a function , But when i called the function
res.redirect('/pageOne');
callBack();
I found that the callBack executed before the redirect,
so there any way to pass callBack to redirect ? according to the api its no. any other workaround ?
I am redirecting to a page using
res.redirect('/pageOne');
so after the redirect i want call a function , But when i called the function
res.redirect('/pageOne');
callBack();
I found that the callBack executed before the redirect,
so there any way to pass callBack to redirect ? according to the api its no. any other workaround ?
Share Improve this question edited Jun 19, 2017 at 15:33 laser 1,37613 silver badges14 bronze badges asked Jul 14, 2013 at 7:00 SarathSarath 9,15612 gold badges54 silver badges86 bronze badges1 Answer
Reset to default 8According to the current implementation, there is no way to pass a callback into the redirect
method. However, since the response object res
inherits from Node's own ServerResponse
, which in turn is a Writable
stream, you can watch for the related events. For example, you might try the finish
event:
Event: 'finish'
When
end()
is called and there are no more chunks to write, this event is emitted.
So, for example,
res.on('finish', callback);
res.redirect('/pageOne');
本文标签: javascriptHow do do a callback after redirect in expressjsStack Overflow
版权声明:本文标题:javascript - How do do a callback after redirect in expressjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744102857a2590946.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论