简体   繁体   English

Sails.js 使用参数重定向

[英]Sails.js redirect with param

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.在 Sails.js 控制器内部从一个路由重定向到另一个路由并同时传输一些数据的最佳方法是什么。 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布鲁诺

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).我的问题是我不知道如何将错误消息(如果发生)传输回另一条路线(因为我想在那里显示它)。

Sails@v0.12 includes flash middleware in form of https://github.com/jaredhanson/connect-flash : Sails@v0.12 包含https://github.com/jaredhanson/connect-flash形式的 flash 中间件:

req.flash('error', payload);
res.redirect(307, '/');
return;

To get the error in another controller:要在另一个控制器中获取错误:

var error = req.flash('error');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM