2014-02-18 39 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