当数据库中找不到数据时,铁路由器设置notFoundTemplate

时间:2015-06-25 23:00:12

标签: meteor iron-router

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

例如,在下面的路线中,当厨师为空时,我想渲染我的'notFound'模板。

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

2 个答案:

答案 0 :(得分: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']
});

答案 1 :(得分:0)

有一个内置的插件。它被称为dataNotFound。它在iron:router guide中提到。