[英]Meteor User update calls router
我在Meteor.users客户端上调用update来更新配置文件,我注意到它在更新后命中了路由器。 我了解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)
它没有明确记录,但是铁路由器的before
钩是反应性的。 通常这就是您想要的,但是我可以看到,如果您更新了用户的个人资料,这将是多么令人讨厌。 我认为一个简单的解决方案是寻找Meteor.userId()
而不是Meteor.user()
。 这可以完成相同的操作,但是在更新用户的个人资料时,ID不会更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.