Iron router: Error: Couldn't find a template named “/” or “”. Are you sure you defined it?

断了今生、忘了曾经 提交于 2019-12-07 16:23:21

问题


I have trouble setting up a simple iron:router example: (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'
});

Starting the server:

meteor

Then I get (client side):

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

What am I doing wrong ?

Note: I get the exact same error if I clone the example application (basic.html and 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

Also:

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

回答1:


Currently, there are two versions of iron:router.

  • iron:router@0.9.4 is the one added by default when you type meteor add iron:router, this version is the latest in the "legacy" branch of iron:router that came up more than one year ago, it's the one that everyone is probably still using, although they should definitely update to...
  • iron:router@1.0.0-preX with X = 4 as of 20/10/2014, which is a complete rewrite of the package intended to be backward compatible, but introducing a new, nicer and polished API. This version will likely be set as default when meteor hits 1.0.0 later this year. The problem is that github page of iron:router shows this particular branch (1.0.0-pre4) along with examples that people believe are usable with 0.9.4.

This means that you are most likely using the wrong version of iron router, remove it with meteor remove iron:router and meteor add iron:router@1.0.0-pre4 instead.

Recommended reading to learn about the latest iron:router syntax :

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

Sometimes the guide is not completely up-to-date with the pre-release version, if you want to keep up with the latest stuff take a look at github issues.



来源:https://stackoverflow.com/questions/26450293/iron-router-error-couldnt-find-a-template-named-or-are-you-sure-you-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!