4

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

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

如何在除LoginRoute之外的每条路由中包含此 mixin ?

4

1 回答 1

2

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

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
    });
  });
});
于 2014-09-04T05:23:32.240 回答