当在数据库中找不到数据时,Iron-router 设置 notFoundTemplate
Iron-router set notFoundTemplate when no data found in database
当我的数据函数 returns 为 null 时如何设置布局。
例如,在下面的路线中,当 chefs 为 null 时,我想渲染我的 'notFound' 模板。
Router.route('/vendors/chefs/:_url', {
template: 'chefs',
data: function() {
var chefs = Chef_db.findOne({url: this.params._url});
return chefs;
}
});
有一个内置插件。它被称为dataNotFound
。 iron:router guide.
中提到了它
看看文档中的 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']
});
当我的数据函数 returns 为 null 时如何设置布局。
例如,在下面的路线中,当 chefs 为 null 时,我想渲染我的 'notFound' 模板。
Router.route('/vendors/chefs/:_url', {
template: 'chefs',
data: function() {
var chefs = Chef_db.findOne({url: this.params._url});
return chefs;
}
});
有一个内置插件。它被称为dataNotFound
。 iron:router guide.
看看文档中的 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'] });