2014-02-18 38 views
0

我打電話更新Meteor.users客戶端更新配置文件,我發現它更新後點擊路由器。我知道Meteor.user()是被動的,因爲我正在更新它,Meteor會相應地更新。但我想我不確定它爲什麼會觸及路由器,特別是當我沒有在該頁面上獲取任何用戶數據時。這裏是我的更新:流星用戶更新呼叫路由器

Meteor.users.update(Meteor.userId(), {$addToSet: {'profile.collection': @id}}) 

完全航線代碼

Meteor.startup -> 
    Session.setDefault 'subpage', '' 

Router.configure 
    layoutTemplate: "layout" 
    loadingTemplate: "loading" 

Router.before -> 
    routeName = @route.name 
    if Meteor.user() or Meteor.loggingIn() 
    if _.include(["index"], routeName) then Router.go('collection') 
    Session.set 'currentPage', routeName 
    else 
    if routeName isnt 'index' then Router.go 'index' 


Router.map -> 
    @route "index", 
    path: "/" 
    @route "collection" 
    @route "discover" 
    @route "playlists" 
    @route "playlist", 
    path: "/playlists/:_id" 
    data: -> 
     # Playlists.findOne(@params._id) 
+1

如果您使用鐵路路由器,一些掛鉤是被動的。請添加路線代碼以獲得更完整的答案。 –

+0

僅僅因爲我在before hook中調用Meteor.user()? – ZDixon

回答

1

它沒有明確記載,但鐵路由器的before鉤反應。通常這就是你想要的,但是我可以看到如果你更新了用戶的配置文件,這將會很麻煩。我認爲一個簡單的解決方案是尋找Meteor.userId()而不是Meteor.user()。這將完成同樣的事情,但是當用戶的配置文件更新時,id不會改變。

+0

有道理,工作。謝謝 – ZDixon