Meteor无法呈现动态模板

时间:2014-10-03 02:03:23

标签: meteor iron

我正在使用Meteor和iron:路由器包。我试图将基本模板渲染到布局模板中,但一直收到错误:

Exception from Tracker recompute function: Error: Couldn't find a template named "/" or "". Are you sure you defined it?

对于我的'/'路线,我有以下内容:

// router.js

Router.configure({
  layout: 'layout'
});

Router.route('/', function () {
  this.render('welcome');
});

我的模板如下:

<!--main.html -->

<head>
  <title>App</title>
</head>

<body>
</body>

<template name='layout'>
  <div id='container'>
    {{> yield}}
  </div>
</template>

<template name='welcome'>
  <p>Welcome</p>
</template>

对于我的软件包,我最初尝试安装iron:router插件。它似乎增加了铁:核心,铁:动态模板和铁:布局。我已经分别添加了每个库:

> meteor list
iron:core              0.3.4  Iron namespace and utilities.
iron:dynamic-template  0.4.1  Dynamically create and update templates and the...
iron:layout            0.4.1  Dynamic layouts which enable rendering dynamic ...
iron:router            0.9.4  Routing specifically designed for Meteor
meteor-platform        1.1.1  Include a standard set of Meteor packages in yo...

1 个答案:

答案 0 :(得分:1)

尝试将router.js修改为:

Router.configure({
  layoutTemplate: 'layout' // layoutTemplate, not layout
});

Router.route('/',{
  // give the the route a name to help it find your welcome template
  // let the default action function render the layout + template for you
  name:"welcome"
});

你也可以摆脱空体,而且你不需要手动添加iron:router依赖关系:首先是包装系统的用途:)< / p>