简体   繁体   English

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

[英]Root route is ignored when I add /admin route in FlowRouter

My home route works when it's by itself: 我的家庭路线本身可以运行:

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'
    });
  }
});

But when I add in my /admin route, surfing to / routes through the admin route instead. 但是当我添加/admin路由时,改为通过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'
    });
  }
});

I know this because of the console logging I'm doing. 我知道这是因为我正在执行控制台日志记录。 When I surf to / with both routes, the console output is Rendering admin . 当我冲浪/有两条路线,控制台输出Rendering admin Why is it doing this, and how can I fix it? 为什么这样做,我该如何解决?

The problem was in my admin route triggers. 问题出在我的管理员路由触发器中。 I was not assigning an array of functions. 我没有分配功能数组。 I'm not clear why this created the side effects I saw, but correcting it fixed the route. 我不清楚为什么会产生我所看到的副作用,但是更正它可以解决问题。

The route with the fixed triggers property looks like this: 具有固定的triggers属性的路由如下所示:

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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM