【问题标题】:Meteor Unable to Render Dynamic TemplatesMeteor 无法渲染动态模板
【发布时间】:2014-10-03 10:09:05
【问题描述】:

我正在使用带有 Iron:router 包的 Meteor。我正在尝试将基本模板渲染到布局模板中,但一直收到错误消息:

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...

【问题讨论】:

  • 就像 saimeunt 写的,你不需要使用 标签

标签: meteor iron


【解决方案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 依赖项:这就是包系统的首要用途 :)

【讨论】:

  • 使用上面的代码时,我似乎还是找不到模板。我可以用{{&gt; welcome}} 渲染它(不使用路由器)。我修复了 layoutTemplate 配置,并尝试在路由中对其进行硬编码),例如eventedmind.github.io/iron-router/#layouts
  • 我尝试重新安装软件包,以防我想办法手动添加它们,因为我很偏执,它们没有出现&gt; meteor list。渲染单个模板时路由器工作正常,只是似乎无法对产量做任何事情。
  • 我似乎有使用这种语法的东西,它似乎没有记录,所以可能已经过时了:Router.route('welcome', { path: '/' }); 谢谢saimeunt!
  • 好吧,这是在 1.0.0 版本中将被弃用的旧语法,您应该坚持使用较新的语法和 meteor add iron:router@1.0.0-pre2 以跟上最前沿的路由器:eventedmind.github.io/iron-router跨度>
猜你喜欢
  • 1970-01-01
  • 2014-12-12
  • 1970-01-01
  • 1970-01-01
  • 2020-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-11
  • 1970-01-01
相关资源
最近更新 更多