Open tomitrescak opened 9 years ago
Not sure, how IR works with waitOn. (I didn't look for their code recently)
In the second route, there is no waitOn. subscriptions.subscribe('adminPracticals').ready()
is true.
Then, IR don't need to waitOn.
So, technically it should not affect IR in anyway. May be IR handles onBeforeAction differently that you or me expect.
Try to post it there too and ask some suggestions from IR. May be, this is a bug IR or may be a way how it is.
@arunoda, I'm not following :/ so it is a problem of Iron Router? I need to prohibit some routes for specific roles and without onBeforeAction I'm doomed ;/
Seems like this is a bug in IR.
I don't want to be mean and I hope you'll understand :/ but it's subscription manager that breaks IR behaviour. With Meteor.subscribe all works fine.
I'm sorry. I can't do anything for that. SubsManager built for specific use case and it's has no direct relationship with IR.
You need to use this.next()
with IR.
See: It works now.
var subscriptions = new SubsManager();
Router.route('/user/home', {
name: 'restrictedHome',
template: 'restrictedHome',
onBeforeAction: function (pause) {
console.log('YES!!!'); // successfully executed
this.next();
},
waitOn: function () {
return [
Meteor.subscribe('adminPracticals')
];
}
});
Router.route('/user/home1', {
name: 'restrictedHome1',
template: 'restrictedHome1',
onBeforeAction: function (pause) {
console.log('NO :((('); // never executed
this.next();
},
waitOn: function () {
return [
subscriptions.subscribe('adminPracticals')
];
}
});
If this doesn't work, may be it's something with your app. May be you need to read the IR manual a bit too.
I'm having the same issue of the global onBeforeAction
not being called if there is a waitOn
subscription from Subs Manager. e.g.
var subs = new SubsManager();
Router.onBeforeAction(function(){
if (!Meteor.userId()) {
return this.redirect('/');
} else {
this.next();
}
}, { except: ['signIn'] });
// This route calls the above onBeforeAction
Router.route('/dashboard', {
name: 'dashboard'
});
// This route does NOT call the onBeforeAction
Router.route('/products', {
name: 'products',
waitOn: function() {
return subs.subscribe('productsList');
}
});
// This route calls the above onBeforeAction
Router.route('/products-meteor', {
name: 'productsMeteor',
waitOn: function() {
return Meteor.subscribe('productsList');
}
});
Want to change to FlowRouter (especially with v2, just around the corner), but this will be a big refactor.
Please see following routes and comments.
subscription manager also break the global Router.onBeforeAction execution.