我的家庭路线单独运行时有效:
FlowRouter.route('/', {
name: 'home',
triggersEnter: [
function(context, redirect) {
var ExperimentsSub, handle, randomExperiment;
console.log('Home triggers');
ExperimentsSub = new SubsManager;
handle = ExperimentsSub.subscribe('randomExperiment');
if (handle.ready && Experiments.find.count) {
randomExperiment = Experiments.findOne;
return redirect('/experiment/' + randomExperiment._id);
}
}
],
action: function() {
console.log('Rendering home');
return BlazeLayout.render('layout', {
content: 'home'
});
}
});
但是当我添加我的/admin
路线时,改为/
通过管理路线浏览路线。
FlowRouter.route('/admin', {
name: 'admin',
triggersEnter: [console.log('Admin triggers'), !Roles.userIsInRole(this.userId, ['admin']) ? FlowRouter.go(FlowRouter.path('login')) : void 0],
action: function() {
console.log('Rendering admin');
return BlazeLayout.render('layout', {
content: 'admin'
});
}
});
我知道这一点是因为我正在做控制台日志记录。当我使用两条路线冲浪时/
,控制台输出为Rendering admin
. 为什么会这样,我该如何解决?