[英]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.