【问题标题】:Route loads notFound briefly first路由加载 notFound 首先简要
【发布时间】:2014-08-09 09:25:36
【问题描述】:

我有一条基于 url 参数搜索收藏项的铁路线。如果找到它,它会将该项作为数据上下文返回,否则它会呈现一个notFound 模板。代码如下所示:

this.route('profileView', {
        path: list_path + '/profiles/:_id',
        fastRender: true,
        waitOn: function() {
            if (Meteor.user()) {
                return [Meteor.subscribe('singleProfile', this.params._id, Session.get("currentListId"))];
            }
        },
        data: function() {
            var profile = Profiles.findOne({
                _id: this.params._id
            });
            if (!profile) {
                this.render("notFound");
            } else
                return profile;
        }
    });

问题是notFound 模板在配置文件返回之前被短暂加载,尽管我认为waitOn 函数会处理这个问题。使用铁路由器获得预期结果的正确模式是什么?谢谢。

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    您是否可能忘记配置 loadingdataNotFound 挂钩?

    Router.onBeforeAction('loading');
    Router.onBeforeAction('dataNotFound');
    

    如果您想了解这里实际发生的情况,请look here

    【讨论】:

      【解决方案2】:

      我必须在数据中检查 this.ready()。更新代码

      this.route('profileView', {
              path: list_path + '/profiles/:_id',
              fastRender: true,
              waitOn: function() {
                  if (Meteor.user()) {
                      return [Meteor.subscribe('singleProfile', this.params._id, Session.get("currentListId"))];
                  }
              },
              data: function() {
                  if(this.ready()){
                      var profile = Profiles.findOne({
                          _id: this.params._id
                      });
                      if (!profile) {
                          this.render("notFound");
                      } else
                          return profile;
                  }
              }
       });
      

      【讨论】:

        猜你喜欢
        • 2018-04-19
        • 1970-01-01
        • 2017-03-29
        • 2016-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-08
        • 1970-01-01
        相关资源
        最近更新 更多