【问题标题】:Iron router data not found not working properly找不到铁路由器数据无法正常工作
【发布时间】:2014-09-22 11:10:23
【问题描述】:

我的路由器文件中有以下代码。

Router.onBeforeAction(mustBeSignedIn, {except: ['home', 'tests']})
Router.onBeforeAction('dataNotFound')
Router.onBeforeAction('loading')

Router.configure ->
  loadingTemplate: 'loading'
  notFoundTemplate: '404'


#define routes
Router.map ->

  @route 'chat',
    path: '/chat/:room_name'
    waitOn: ->
      [Meteor.subscribe('rooms'),
      Meteor.subscribe('users'),
      Meteor.subscribe('bookmarks', @params.room_name),
      Meteor.subscribe('notifications'),
      Meteor.subscribe('usersNoteCount'),
      Meteor.subscribe('system_messages', @params.room_name)]
    data: ->
      Rooms.findOne({room_name: @params.room_name})

每当我遇到特定房间不存在的情况时,当数据为nullundefined 时,页面仍会尝试呈现聊天页面。

我不知道如何解决这个问题,因为我阅读的所有内容都告诉我这是处理未找到页面的确切方法。

编辑

通过上面的代码编辑,我仍然遇到一个问题,我要么永远加载,要么我摆脱了需要参数的两个订阅,我看到加载时出现空白页面。我在这里做错了什么?

我觉得我需要在发布方面修复永久加载问题,但我仍然不完全确定如何修复它。

【问题讨论】:

  • 但这不是一个未找到的页面 - 即使房间名称不在数据库中,路径也将完全有效,它只是没有任何关联的数据。问题是您需要处理数据上下文为空的情况,无论是在页面本身上还是使用 David Weldon 提到的 dataNotFound 方法。

标签: coffeescript meteor iron-router


【解决方案1】:

目前似乎无法正常工作。

https://github.com/EventedMind/iron-router/issues/745

【讨论】:

    【解决方案2】:

    按照docs 中的建议,您需要添加Router.onBeforeAction('dataNotFound')。试一试,告诉我进展如何。

    【讨论】:

    • 我刚刚更新了代码以反映我仍然遇到的问题。
    猜你喜欢
    • 2014-07-10
    • 2018-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 2019-12-31
    • 2016-11-26
    • 2014-12-05
    相关资源
    最近更新 更多