0

我的家庭路线单独运行时有效:

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. 为什么会这样,我该如何解决?

4

1 回答 1

0

问题出在我的管理路由触发器中。我没有分配函数数组。我不清楚为什么这会产生我看到的副作用,但纠正它会修复路线。

具有固定触发器属性的路由如下所示:

FlowRouter.route '/admin',
  name: 'admin'
  triggersEnter: [ (context, redirect) ->
    console.log 'Admin triggers'
    unless Roles.userIsInRole this.userId, ['admin']
      redirect FlowRouter.path('login')
  ]
  action: ->
    console.log 'Rendering admin'
    BlazeLayout.render 'layout', content: 'admin'
于 2015-11-28T00:19:48.387 回答