gpt4 book ai didi

ember.js - Ember : Add mixin to every route except one

转载 作者:行者123 更新时间:2023-12-01 03:47:27 27 4
gpt4 key购买 nike

在 Ember-Cli 应用程序中使用 Ember-Simple-Auth,我试图在我的应用程序中的几乎每条路由上都要求进行身份验证。我不想使用 AuthenticatedRouteMixin在每条路线上,因为我不想定义每条路线。所以我将 mixin 添加到 ApplicationRoute。

但是,这会导致无限循环,因为显然登录路由是从同一个 ApplicationRoute 延伸出来的,因此现在受到保护。

我如何在除 LoginRoute 之外的每个路由中包含这个 mixin?

最佳答案

我怀疑您在每条路线上都需要它,很可能您只需要它作为经过身份验证的资源的大门。

App.Router.map(function(){
this.route('login'); // doesn't need it
this.resource('a', function(){ <-- need it here
this.resource('edit'); <-- this is protected by the parent route
});
this.resource('b', function(){ <-- and here
this.resource('edit'); <-- this is protected by the parent route
});
});

或者你可以更深入一层,然后创建一个包含所有内容的路由:
App.Router.map(function(){
this.route('login'); // doesn't need it
this.resource('authenticated', function(){ <-- put it here
this.resource('a', function(){ <-- this is protected by the parent route
this.resource('edit'); <-- this is protected by the grandparent route
});
this.resource('b', function(){ <-- this is protected by the parent route
this.resource('edit'); <-- this is protected by the grandparent route
});
});
});

关于ember.js - Ember : Add mixin to every route except one,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25656204/

27 4 0
文章推荐: jquery - fancybox 错误 - 对象 # 没有方法 'undelegate'