【发布时间】:2015-09-27 23:00:37
【问题描述】:
我在我的流星应用程序中使用 Iron-Route 进行路由。由于我有多个模块并且我想避免多个编码,因此我将用于身份验证(角色)的过滤器放入核心包中:
核心包
var filters = {
authenticate: function () {
var user;
if (Meteor.loggingIn()) {
this.layout('login');
this.render('loading');
} else {
user = Meteor.user();
if (!user) {
this.layout('login');
this.render('signin');
return;
}
this.layout('StandardLayout');
this.next();
}
}
}
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
notFoundTemplate: 'notFound',
before: filters.authenticate
});
Router.route('/', function () {
this.render('contentTemplate', { to: 'content' });
this.render('navigationTemplate', { to: 'navigation' },)
});
其他包
...只需要这个:
Router.route('/article/:_id', {
name: 'article',
yieldTemplates: {
'navigationPage': { to: 'navigation' },
'contentPage': { to: 'content' }
}
});
现在在显示任何内容之前都会检查每个模块(路线)。
但我需要头版例外。主页Route.route('/') 也应该由未登录的用户访问。我该怎么做?
【问题讨论】:
标签: javascript meteor iron-router