0

我已经设置了路线

this.route('force', {
 path: '/force',
 template: 'showForce',
 layoutTemplate: 'mainpanel'
});

模板showForce非常简单

<template name="showForce">
  <p>show force</p>
</template>

mainPanel模板一样

 <template name="mainpanel">
   {{ yield }}
 </template>

但是该模板有这样的父级

<template name="page_logged_in">
  {{> header}}

  <div id="side-panel">
    {{> sidepanel}}
  </div>

  <div id="main-panel">
    {{> mainpanel}}
  </div>
</template>

该路由确实将模板呈现到页面但不在yield位置中。它显示为page_logged_in模板的 DOM 兄弟。

任何想法为什么会发生这种情况?

谢谢

4

2 回答 2

1

Iron Router 有点难以适应。您应该使用命名的 yield 功能并让 Iron Router 放入模板,而不是尝试使用 {{> templateName}} 插入。我根据您的代码创建了一个演示存储库,以展示如何实现您想要的结果,它位于:https ://github.com/copleykj/ConnorAtherton

于 2013-12-19T06:24:00.177 回答
0

不要忘记也进行路由器配置

Router.configure({
    layoutTemplate: 'mainpanel'
});

你的路线也应该是这样的

this.route('showForce', {
    path: '/force',
    layoutTemplate: 'mainpanel'
});

“模板”应该是第一个参数。如果没有配置 layoutTemplate,我认为 Iron 路由器使用 body 作为产量,这就是为什么您可能会看到 dom 移位的原因。

于 2013-12-16T23:49:52.380 回答