EmberJS:如何从路由重定向,保持查询参数

时间:2015-07-10 17:07:27

标签: redirect ember.js ember-data

我想从路线new重定向,并保留queryParams路线的查询参数:

据我所知,访问model的唯一地方是在路线的import Ember from "ember"; export default Ember.Route.extend({ /** * @@override * Implicitly create a new applicant, redirecting to the generated ID at /applications/#{id} * @param transition */ beforeModel: function(transition) { var emptyApplicant = this.store.createRecord("applicant", {isPrimary: true} ), emptyApplication = this.store.createRecord("application"); emptyApplication.set("applicant", emptyApplicant); emptyApplicant.save().then((savedApplicant) => { emptyApplication.save().then((savedApplication) => { this.transitionTo("applications", savedApplication); }); }); } }); 挂钩范围内。

但我想重新定位beforeModel hook

applicants/new?agent=35

虽然上述代码有效,但转换将完成而不保留查询参数。例如,导航到agent=35不会在查询参数中保留applicants/new,而只会重定向到queryParams

如何从我的Ember应用程序中的beforeModel挂钩中访问[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mymagazine1://"]] 对象?

2 个答案:

答案 0 :(得分:9)

您应该能够将query parameters传递给... group new { apt, cls, prg, city } by new{apt.Gender} into grouped select new CityWiseStudentModel { CityNames = grouped.Select(g => g.city.CityName), ... programNames = grouped.Select(g => g.prg.Program) } ,其中包含以下内容:

transitionTo

答案 1 :(得分:0)

在更现代的Ember版本中,包含查询参数的transition object has a to property。过渡不再具有queryParams属性

例如,重定向到index中的beforeModel路由可能看起来像这样:

beforeModel(transition){
  super.beforeModel(...arguments);
  transition.abort();
  this.transitionTo('index', {
    queryParams: transition.to.queryParams
  });
}