Reputation: 667
Is there a way I can determine if a given route is the child of the current route?
I'm using the willTransition hook in a Route to determine whether I should display a data-loss confirmation message when the user transitions away from this route. I don't want this data-loss confirmation to execute if the user transitions between various child resources and routes contained within this resource's router map, but I cannot find a way to determine if the transition I'm given in willTransition is a child of this.routeName.
Any suggestions?
Router:
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
}
}
});
Upvotes: 2
Views: 827
Reputation: 4334
How about
Ember.Route.extend({
actions: {
willTransition: function(transition) {
if (transition.get('targetName').indexOf(this.get('routeName')) === false) {
// moving to a sibling or higger route
}
}
}
});
May need adjustments according to your route names.
Upvotes: 1