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