【问题标题】:Iron-router set notFoundTemplate when no data found in database在数据库中找不到数据时,Iron-router 设置 notFoundTemplate
【发布时间】:2015-06-25 23:00:12
【问题描述】:

当我的数据函数返回 null 时如何设置布局。

例如,在下面的路由中,当 chefs 为 null 时,我想渲染我的 'notFound' 模板。

Router.route('/vendors/chefs/:_url', {
  template: 'chefs',
  data: function() {
    var chefs = Chef_db.findOne({url: this.params._url});
    return chefs;
  }
});

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    看看文档中的notFoundTemplate:https://github.com/iron-meteor/iron-router/blob/devel/Guide.md

    你可以全局应用它:

    Router.plugin('dataNotFound', {notFoundTemplate: 'notFound'});

    或者您可以使用 except/only 选项将其应用于特定路线:

    Router.plugin('dataNotFound', {
      notFoundTemplate: 'NotFound', 
      except: ['server.route']
      // or only: ['routeOne', 'routeTwo']
    });
    

    【讨论】:

      【解决方案2】:

      为此有一个内置插件。它被称为dataNotFoundiron:router guide中提到过。

      【讨论】:

        猜你喜欢
        • 2014-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多