[英]Meteor User update calls router
I'm calling update on Meteor.users client side to update the profile and I noticed it hits the Router after the update. 我在Meteor.users客户端上调用update来更新配置文件,我注意到它在更新后命中了路由器。 I understand that Meteor.user() is reactive, and since I'm updating it, Meteor will update accordingly.
我了解Meteor.user()是反应性的,并且由于我正在更新它,因此Meteor将相应地更新。 But I guess I'm not sure why it's hitting the router, especially when I'm not getting any of the user's data on that page.
但是我想我不确定为什么它会打中路由器,尤其是当我在该页面上没有获得任何用户数据时。 Here's my update:
这是我的更新:
Meteor.users.update(Meteor.userId(), {$addToSet: {'profile.collection': @id}})
Complete routes code 完整的路线代码
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)
It isn't clearly documented, but iron router's before
hook is reactive. 它没有明确记录,但是铁路由器的
before
钩是反应性的。 Usually this is what you want, but I can see how this would be annoying if you updated the user's profile. 通常这就是您想要的,但是我可以看到,如果您更新了用户的个人资料,这将是多么令人讨厌。 I think an easy solution is to look for
Meteor.userId()
instead of Meteor.user()
. 我认为一个简单的解决方案是寻找
Meteor.userId()
而不是Meteor.user()
。 This accomplishes the same thing but the id won't change when the user's profile is updated. 这可以完成相同的操作,但是在更新用户的个人资料时,ID不会更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.