如果你想只为授权用户发布数据,您检查(如果用户进行身份验证)的路线,在onBeforeAction是可能的。喜欢的东西:
Router.map(function(){
this.route('home', {
path : '/',
template : 'home'
});
this.route('register', {
path : '/register',
template : 'register'
});
this.route('login', {
path : '/login',
template : 'login'
});
this.route('requestlisting', {
path : '/requestlisting',
template : 'requestlisting',
waitOn : function(){
return Meteor.subscribe('RequestsPublication');
}
});
...
});
var requireLogin = function() {
if(!Meteor.user()){
if(Meteor.loggingIn()){
this.render(this.loadingTemplate);
}else{
Router.go('login');
}
} else {
this.next();
}
}
Router.onBeforeAction(requireLogin, {only: ['requestlisting',...]});
在这个例子中,在onBeforeAction,路由发生了“requestlisting”只有当用户登录后,话很有道理订阅任何数据。
感谢槟榔这么一个简洁的解释,但'订阅'呢? –