【问题标题】:Iron Router / Meteor : Except not working铁路由器/流星:除了不工作
【发布时间】:2014-11-23 03:45:12
【问题描述】:

我正在尝试让登录过程正常工作。基本上,如果用户没有登录,所有路由都应该重定向到“/login”。除了“/signup”和“/reset”,因为如果你去那里你显然不会登录。

Router.configure({
  layoutTemplate: 'layout'
});

Router.onBeforeAction(function () {

  except: ['signup','reset']
  if (!Meteor.userId()) {
    // if the user is not logged in, render the Login template
    this.render('login');
    }
  else {
      this.next();
  }
});

Router.route('/', function (){
  this.render('app-main-page');
});

Router.route('/signup', function () {
  this.render('signup');},
  {
    name:'signup'
  });

Router.route('/reset', function () {
  this.render('reset');},
  {
    name:'reset'
  });

// and a bunch of more routes within the app 

});

一般来说,onBeforeAction 是有效的,当有人没有登录时,登录模板会被渲染。但是,“例外”部分不起作用,这意味着用户无法注册,因为他们被重定向到登录页面。有没有人有任何见解?这似乎是一段非常简单的代码,我完全不知道我可能在哪里出错。

【问题讨论】:

    标签: meteor iron-router iron


    【解决方案1】:
    onBeforeAction: function() {
        ..
    
        this.next();
    }
    

    使用this,nexr() 离开onBeforeAction ,

    【讨论】:

      猜你喜欢
      • 2014-09-07
      • 1970-01-01
      • 2016-01-22
      • 2014-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      相关资源
      最近更新 更多