2014-09-04 51 views
4

在Ember-Cli应用中使用Ember-Simple-Auth,我试图在我的应用程序中的几乎每条路由上要求身份验证。我不想在每条路线上使用AuthenticatedRouteMixin,因为我不想定义每条路线。所以我添加了mixin到ApplicationRouteEmber:添加mixin到除了一个之外的每条路由

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

如何在每条路线中包含此mixin,但登录路线

回答

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

是啊。这正是我正在寻找的。我可能会补充说我在验证过的资源上定义了一个空路径'{path:''}',这样我的url看起来和以前一样。谢谢! – niftygrifty 2014-09-09 06:05:28

相关问题