2014-09-04 46 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

相關問題