what is the best way to redirect inside a Sails.js Controller from one route to another and transfer some data at the same time. My situation is that I've got one route that creates some data and the redirects back to another route. My problem is that I don't know how to transfer an error message (if one happens) back to the other route (because I want to display it there).
Bruno
答案 0 :(得分:1)
我的问题是我不知道如何传输错误消息(如果 一个发生)回到另一条路线(因为我想显示它 有)。
Sails@v0.12包含https://github.com/jaredhanson/connect-flash形式的flash中间件:
req.flash('error', payload);
res.redirect(307, '/');
return;
要在另一个控制器中获取错误:
var error = req.flash('error');