Meteor 卡在加载模板上

Meteor 卡在加载模板上,meteor,Meteor,嘿,我有一个系统,一个登录的用户可以在一个“战斗”中,一旦他们,我希望用户被锁定在一个给定的模板上,直到战斗结束 我有 # # Currently active battle # Meteor.publish 'activeBattle', -> character = Characters.findOne(userId: this.userId) if this.userId and character return Battles.find({active: true,

嘿,我有一个系统,一个登录的用户可以在一个“战斗”中,一旦他们,我希望用户被锁定在一个给定的模板上,直到战斗结束

我有

#
# Currently active battle
#
Meteor.publish 'activeBattle', ->
  character = Characters.findOne(userId: this.userId)
  if this.userId and character
    return Battles.find({active: true, $or: [{characterOneId: character._id}, {characterTwoId: character._id}]})
  else
    return
在我的铁路由器里

Router.configure
  layoutTemplate: 'layout'
  loadingTemplate: 'loading'
  waitOn: [
    Meteor.subscribe('activeBattle')
  ]

...

redirectToActiveBattle = (pause) ->
  battle = Battles.findOne(active: true)
  if battle and Meteor.userId()
    throwError('You have a battle in progress.')
    Router.go('combat', {_id: battle._id})
    pause()

...

Router.onBeforeAction(redirectToActiveBattle, except: ['login', 'logout', 'signup', 'combat'])

当用户登录并且有一个字符时,此操作有效,但如果没有,页面将被粘贴在加载模板上,而不是显示登录屏幕。实际上,您应该使用
This.ready()而不是空返回。因此,正确的出版方式可能是:

Meteor.publish 'activeBattle', ->
  character = Characters.findOne(userId: this.userId)
  if this.userId and character
    return Battles.find({active: true, $or: [{characterOneId: character._id}, {characterTwoId: character._id}]})
  this.ready()

publish
else
子句中,尝试
return[]
而不是
return