ember.js:从 AuthenticatedRouteMixin 生成 AdminRouteMixin?
ember.js: Make AdminRouteMixin from AuthenticatedRouteMixin?
有没有比在我的所有管理路由中都写这个更优雅的方法来防止未经授权访问仅管理路由?
export default Ember.Route.extend(AuthenticatedRouteMixin, {
beforeModel: function(){
if(!this.get('session.secure.admin')) this.transitionTo("dashboard");
}
});
也许可以扩展 AuthenticatedRouteMixin
本身来进行这种检查?
谢谢!
为什么不直接制作 mixin?
import Ember from 'ember';
import AuthenticatedRouteMixin from 'wherever/it/is'.
const { Mixin } = Ember;
export default Mixin.create(AuthenticatedRouteMixin, {
beforeModel(){
if(!this.get('session.secure.admin')) {
this.transitionTo("dashboard");
}
}
})
然后在你的路由中导入它:
import Ember from 'ember';
import AdminCheckMixin from 'yourApp/mixins/routes/admin-check';
const { Route } = Ember;
export default Route.extend(AdminCheckMixin);
有没有比在我的所有管理路由中都写这个更优雅的方法来防止未经授权访问仅管理路由?
export default Ember.Route.extend(AuthenticatedRouteMixin, {
beforeModel: function(){
if(!this.get('session.secure.admin')) this.transitionTo("dashboard");
}
});
也许可以扩展 AuthenticatedRouteMixin
本身来进行这种检查?
谢谢!
为什么不直接制作 mixin?
import Ember from 'ember';
import AuthenticatedRouteMixin from 'wherever/it/is'.
const { Mixin } = Ember;
export default Mixin.create(AuthenticatedRouteMixin, {
beforeModel(){
if(!this.get('session.secure.admin')) {
this.transitionTo("dashboard");
}
}
})
然后在你的路由中导入它:
import Ember from 'ember';
import AdminCheckMixin from 'yourApp/mixins/routes/admin-check';
const { Route } = Ember;
export default Route.extend(AdminCheckMixin);