【问题标题】:Iron router: Error: Couldn't find a template named "/" or "". Are you sure you defined it?Iron 路由器:错误:找不到名为“/”或“”的模板。你确定你定义了吗?
【发布时间】:2014-10-20 06:09:54
【问题描述】:

我无法设置一个简单的 Iron:router 示例:(docs, sample app)

meteor create testapp
cd testapp

home.html

<template name="Home">
  <h1>Welcome</h1>
  home
</template>

router.js

Router.route('/', function () {
  this.render('Home'); // Also tried 'home'
});

启动服务器:

meteor

然后我得到(客户端):

Exception from Tracker recompute function: Error: Couldn't find a template named "/" or "". Are you sure you defined it?
    at null._render (http://localhost:3000/packages/iron_dynamic-template.js?32038885cb1dad7957291ffebfffcb7f8cd57d20:239:17)
    at doRender (http://localhost:3000/packages/blaze.js?88aac5d3c26b7576ac55bb3afc5324f465757709:1853:25)
    ...

我做错了什么?

注意:如果我克隆 the example application(basic.html 和 basic.js),我会得到完全相同的错误。

meteor list
autopublish      1.0.1  Publish the entire database to all clients
insecure         1.0.1  Allow all database writes by default
iron:router      0.9.4  Routing specifically designed for Meteor
meteor-platform  1.1.2  Include a standard set of Meteor packages in your app

还有:

meteor --version
Meteor 0.9.4 <- Why all standard packages and meteor platform are > 1.0 and this is 0.9.4 ?

【问题讨论】:

  • 您使用的是错误版本的 Iron 路由器,删除它并添加 iron:router@1.0.0-pre4 代替。
  • @saimeunt 非常感谢,这就是问题所在。当您使用与当前版本的流星不兼容的包时,确实应该更明显。
  • 它实际上是 Iron 路由器,并没有明显表明它的示例是使用 1.0.0 预发行版设计的,而不是 Iron:router@0.9.4。
  • @saimeunt 回答这个问题,我遇到了同样的问题,需要给你点赞。
  • 添加了关于这些iron:router 版本控制问题的说明。

标签: meteor iron-router meteor-0.9.4


【解决方案1】:

目前iron:router有两个版本。

  • iron:router@0.9.4是输入meteor add iron:router时默认添加的,这个版本是一年多前出现的iron:router的“legacy”分支中的最新版本,可能大家还在使用,虽然他们肯定应该更新到...
  • iron:router@1.0.0-preXX = 4 截至 20/10/2014,这是对包的完全重写,旨在向后兼容,但引入了一个新的、更好的和抛光的 API。当今年晚些时候流星发布 1.0.0 时,此版本可能会被设置为默认版本。问题是iron:router 的 github 页面显示了这个特定的分支 (1.0.0-pre4) 以及人们认为可以与 0.9.4 一起使用的示例。

这意味着您很可能使用了错误版本的 Iron 路由器,请使用 meteor remove iron:routermeteor add iron:router@1.0.0-pre4 将其删除。

推荐阅读了解最新的iron:router语法:

http://eventedmind.github.io/iron-router/

有时该指南与预发布版本不完全同步,如果您想了解最新信息,请查看 github 问题。

【讨论】:

  • 非常感谢:D,你让我很开心:P
  • 我们也有同样的问题,但在 iron:router@1.0.12 上,而且只在移动设备上知道吗?
猜你喜欢
  • 1970-01-01
  • 2018-11-21
  • 2015-02-12
  • 2022-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-05
  • 1970-01-01
  • 2010-10-13
相关资源
最近更新 更多