2015-07-20 22 views
0

我有一个路由器地图下面的代码:困惑流星this.next()错误onBeforeAction

this.route('confirmTag', { 
    path: '/confirm-tag', 
    template: 'confirmTag', 
    controller: 'SignUpController', 
    onBeforeAction: function() { 
     if (Meteor.user()) { 
      if (typeof user.profile.tag === 'undefined') { 
       Router.go('confirm'); 
      } else { 
       Router.go('checkEmail'); 
      } 
      this.next(); 
     } else { 
      Router.go('signUp'); 
     } 
     this.next(); 
    } 
}); 

不过,我不断收到此错误控制台:

Exception in callback of async function: 
[email protected]://localhost:3000/lib/router.js?783dc96a24a92cfd09fbf0ca371d762661a830bb:87:9 

87号线在示例代码是:

if (typeof user.profile.tag === 'undefined') { 

“this.next();”应该怎么做?置于上面的代码中?

在此先感谢。

+0

我无法想象调用'this.next()'是个好主意。 –

+0

当使用onBeforeAction – mayvn

+0

时,this.next()实际上是需要的,但是在你的'if'的真正分支中,你要调用它两次。但也许这毕竟不是问题。 –

回答

1

我没有看到在任何地方定义的user。那么...

this.route('confirmTag', { 
    path: '/confirm-tag', 
    template: 'confirmTag', 
    controller: 'SignUpController', 
    onBeforeAction: function() { 
     if (Meteor.user()) { 
      var user = Meteor.user(); 
      if (typeof user.profile.tag === 'undefined') { 
       Router.go('confirm'); 
      } else { 
       Router.go('checkEmail'); 
      } 
      this.next(); 
     } else { 
      Router.go('signUp'); 
     } 
     this.next(); 
    } 
}); 
+0

你是对的..我应该抓住那个。在盯着代码这么久之后迷失了方向。谢谢! – mayvn