【发布时间】:2015-01-19 22:21:33
【问题描述】:
有没有办法确定给定路线是否是当前路线的子路线?
我在 Route 中使用 willTransition 挂钩来确定当用户离开此路由时是否应该显示数据丢失确认消息。如果用户在此资源的路由器映射中包含的各种子资源和路由之间进行转换,我不希望执行此数据丢失确认,但我找不到方法来确定我在 willTransition 中给出的转换是否是这个.routeName。
有什么建议吗?
路由器:
Router.map(function() {
this.route('some-route')
this.resource('parent-resource', function() {
this.route('child-route');
this.resource('child-resource', function() {
this.route('child-resource-route1');
this.route('child-resource-route2');
}
}
});
ParentResourceRoute:
Ember.Route.extend({
actions: {
willTransition: function(transition) {
// if transition is not a child of this.routeName display a confirmation alert if there is dirty data
}
}
});
【问题讨论】:
-
我不会把它放在 willTransition 中,我宁愿在父路由中创建一个子路由(知道发生了什么的路由)可以调用以显示警报的方法。
-
我不太确定在这种情况下是否可行。在子路由之间转换时,我不希望发生任何确认。我唯一关心确定是否存在脏数据的时间是离开父资源路由并转到其兄弟姐妹之一时。如果我从子路由进行检查,我怎么知道我是否要在父资源之外转换?
标签: javascript ember.js ember-router