【发布时间】:2016-01-13 02:29:21
【问题描述】:
我正在将 Meteor 与 FlowRouter 一起使用,但我遇到了一个奇怪的行为。我想知道我是否只是从根本上不理解某些东西。我在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");
}
}
我运行meteor 并转到localhost:3000 并查看控制台,我看到“Worked”表示 isUserLoggedIn 函数已被触发。我没有点击管理员或去localhost:3000/admin。只到顶层。为什么我没有去/admin路由时会触发isUserLoggedIn函数?
编辑 1:看起来我的简化示例实际上运行良好。实际问题其实有点像这样:
"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");
}
}
似乎不可能通过 triggersEnter 传递参数(或者我不知道如何使其正常工作)。有没有办法通过 triggersEnter 发送参数?
【问题讨论】:
标签: javascript meteor meteor-blaze flow-router