2014-07-17 54 views
0

我有一個名爲onBeforeAction的函數來設置會話變量頁面標題。我想將它發送給模板的數據。我怎樣才能從路由器訪問這些數據?鐵路由器:訪問路由器功能中的路由數據

我已經試過這樣的事情:

this.route('userPage', { 
    path: '/profile/:userId', 
    waitOn: function() { 
     return [ 
      Meteor.subscribe('singleUser', this.params.userId) 
     ]; 
    }, 
    data: function() { 
     return { 
      user: Meteor.users.findOne({_id: this.params.userId}, {fields: {'username': 1, 'profile.friends': 1}}) 
     }; 
    }, 
    onBeforeAction: function() { 
     Session.set('pageTitle', this.data.user.username); //THIS 
    } 
}); 

有什麼建議?

回答

1

這裏,this.data是一個函數。試試這個:

Session.set('pageTitle', this.data().user.username); 
+0

當然。所以當你點擊鏈接時,它會有點作用,但由於某種原因導致導航斷開(如果你點擊返回按鈕)... – oliv23

+0

看看你的瀏覽器控制檯是否有錯誤。可能有些部分需要被保護,如:'this.data()&& this.data()。user && this.data()。user.username' –