【发布时间】:2015-02-14 01:41:05
【问题描述】:
所以我刚刚开始使用 Iron-router,我一直在构建一个登录系统。它在每条路线之前通过 .onBeforeAction 挂钩工作,检查用户是否已登录。但是,我希望公开一些路线,因此根据文档,我添加了一个 except 选项。除了问题是它不起作用:(有人能明白为什么吗?
Router.route('/new', function () {
name: 'new',
this.render('newComp');
});
Router.route('/c/:_id', {
name: 'compPage',
data: function() { return Comps.findOne(this.params._id); }
});
Router.route('/c/:_id/embed', function () {
name: 'embed',
this.layout('empty'),
this.render('compEmbed', {
data: function () {
return Comps.findOne({_id: this.params._id});
}
});
});
function loginFunction(){
// all properties available in the route function
// are also available here such as this.params
if (!Meteor.user()) {
// if the user is not logged in, render the Login template
if (Meteor.loggingIn()) {
this.render(this.loadingTemplate);
} else {
this.layout('empty');
this.render('login');
}
} else {
// otherwise don't hold up the rest of hooks or our route/action function
this.next();
}
}
Router.onBeforeAction( loginFunction, {
except: ['embed'] // this aint working
});
【问题讨论】:
标签: meteor routing iron-router