【发布时间】:2015-07-10 17:07:26
【问题描述】:
我想从路由 /new 重定向,并保留 new 路由的查询参数:
据我所知,访问queryParams 的唯一位置是在路由的model 挂钩内。
但我想重定向到beforeModel hook:
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);
});
});
}
});
虽然上述代码有效,但转换将完成不保留查询参数。例如,导航到applicants/new?agent=35 不会在查询参数中保留agent=35,而只会重定向到applicants/new。
如何在我的 Ember 应用程序中通过 beforeModel 挂钩访问 queryParams 对象?
【问题讨论】:
标签: redirect ember.js ember-data