2015-07-20 55 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