gpt4 book ai didi

javascript - Ember Router - 确定路由/资源是否是当前路由的子路由

转载 作者:行者123 更新时间:2023-11-30 05:31:01 25 4
gpt4 key购买 nike

有什么方法可以确定给定路由是否是当前路由的子路由?

我在路由中使用 willTransition Hook 来确定当用户离开此路由时是否应显示数据丢失确认消息。如果用户在此资源的路由器映射中包含的各种子资源和路由之间转换,我不希望执行此数据丢失确认,但我无法找到一种方法来确定我在 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');
}
}
});

父资源路由:

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
}
}
});

最佳答案

怎么样

Ember.Route.extend({
actions: {
willTransition: function(transition) {
if (transition.get('targetName').indexOf(this.get('routeName')) === false) {
// moving to a sibling or higger route
}
}
}
});

可能需要根据您的路线名称进行调整。

关于javascript - Ember Router - 确定路由/资源是否是当前路由的子路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27066997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com