【问题标题】:Root route is ignored when I add /admin route in FlowRouter当我在 FlowRouter 中添加 /admin 路由时,根路由被忽略
【发布时间】:2015-11-28 08:19:48
【问题描述】:

我的家乡路线在它自己时有效:

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

【问题讨论】:

    标签: javascript meteor flow-router


    【解决方案1】:

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

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

    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'
    

    【讨论】:

      猜你喜欢
      • 2014-04-23
      • 2011-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多