Objective : I want to render one among template A or template B from my flow router function, based upon a document which is retrieved after a subscribe call.
More specifically, I want to render either an admin or a student template based upon the isAdmin field of a user document, retrieved after a completed subscribe call. My router function is as shown below.
FlowRouter.route('/songs/list', {
name: 'Songs.list',
subscriptions: function(params, queryParams) {
this.register('getUser', Meteor.subscribe('allUsers', Meteor.userId()));
}
action(params, queryParams) {
if(Meteor.user().isAdmin){
BlazeLayout.render("admin_home");
}
else{
BlazeLayout.render("student_home");
}
}
});
The Flow router documentation mentions specifically that
FlowRouter only deals with registration of subscriptions. It does not wait until subscription becomes ready.
So there could be a case where the "if condition" is evaluated before the subscription has updated the local cache.
With iron-router, this is easily handled using a waitOn. However for flow router, I am forced to have 2 separate functions, which further enforces 2 separate url's, for rendering the admin and student templates.
Is this a design choice made by the flow router developers?