Javascript Meteor用户更新呼叫路由器
我在Meteor.users客户端调用更新来更新配置文件,我注意到它在更新后会击中路由器。我知道Meteor.user()是被动的,因为我正在更新它,Meteor将相应地更新。但我想我不知道为什么它会击中路由器,尤其是当我没有在该页面上获取任何用户数据时。以下是我的更新:Javascript Meteor用户更新呼叫路由器,javascript,meteor,Javascript,Meteor,我在Meteor.users客户端调用更新来更新配置文件,我注意到它在更新后会击中路由器。我知道Meteor.user()是被动的,因为我正在更新它,Meteor将相应地更新。但我想我不知道为什么它会击中路由器,尤其是当我没有在该页面上获取任何用户数据时。以下是我的更新: Meteor.users.update(Meteor.userId(), {$addToSet: {'profile.collection': @id}}) 完整路线代码 Meteor.startup -> Ses
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)
它没有明确的文档记录,但iron router的
之前的钩子是被动的。通常这是你想要的,但我可以看出如果你更新了用户的个人资料,这会多么烦人。我认为一个简单的解决方案是寻找Meteor.userId()
,而不是Meteor.user()
。这实现了同样的功能,但当用户的配置文件更新时,id不会改变。如果您使用的是iron router,则某些挂钩是被动的。请添加路由代码以获得更完整的答案。这仅仅是因为我在before钩子中调用Meteor.user()吗?