I am using Meteor with FlowRouter and I am getting a strange behavior. I am wondering if I am just fundamentally not understanding something. I have the following code in client/route.js
:
"use strict";
FlowRouter.route('/', {
name: 'home',
action: function() {
BlazeLayout.render('main', {main: "homePage"});
}
});
FlowRouter.route('/admin', {
name: 'admin',
triggersEnter: [isUserLoggedIn],
action: function() {
BlazeLayout.render('main', {main: "admin"});
}
});
function isUserLoggedIn() {
console.log("Worked");
if (Meteor.userId()) {
route = FlowRouter.current();
} else {
FlowRouter.go("home");
}
}
I run meteor
and I go to localhost:3000
and I look at the console, I see "Worked" meaning that the isUserLoggedIn function has been triggered. I have NOT clicked on admin or gone to localhost:3000/admin
. Only to the top level. Why would the isUserLoggedIn function be triggered when I have not gone to the /admin
route?
Edit 1: It would seem my simplified example actually does work pretty well. The actual problem is actually a bit more like this:
"use strict";
FlowRouter.route('/', {
name: 'home',
action: function() {
BlazeLayout.render('main', {main: "homePage"});
}
});
FlowRouter.route('/admin', {
name: 'admin',
triggersEnter: [isUserLoggedIn(role)],
action: function() {
BlazeLayout.render('main', {main: "admin"});
}
});
function isUserLoggedIn(role) {
console.log("Worked");
if (Meteor.userId() && Role.userIsInRole(role)) {
route = FlowRouter.current();
} else {
FlowRouter.go("home");
}
}
Passing a parameter through the triggersEnter doesn't seem to be possible (or I am not aware of how to make it work properly). Is there a way to send a parameter through the triggersEnter?