在FlowRouter中添加/ admin路由时,将忽略根路由

时间:2015-11-27 16:18:48

标签: javascript meteor flow-router

我的家乡航线本身就有效:

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

1 个答案:

答案 0 :(得分: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'