简体   繁体   中英

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. I understand that Meteor.user() is reactive, and since I'm updating it, Meteor will update accordingly. 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. 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() . This accomplishes the same thing but the id won't change when the user's profile is updated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM