如何显示模板而不在布局模板中显示它?

How to display a template without displaying it inside the layout template?

也许我的问题有点不清楚,但我相信你会明白的。

所以在我的 Ironrouter 配置中,我有以下代码:

Router.configure({
  layoutTemplate: 'layout',
  notFoundTemplate: '404',
  loadingTemplate: 'loading',
  fastRender: true,
});

当我想显示 404 错误时,它会在 layout 模板中插入 404 错误模板,所以它有点难看:

布局为左侧菜单和顶部栏 + 页脚。这是模板,因为我到处都用这个。

那么如何只显示模板 404 而不将其放入模板 layout 中?

没有干净的方法可以做到这一点,但我过去曾使用过这种技巧。使用这样的路由定义,其中 'errorLayout' 指的是一个模板,该模板是仅针对 404 错误的特殊布局。

Router.route('/(.*)', function() {
   this.layout('errorLayout');
   this.render('404');
   this.next();
});

黑客最初来自 here