javascript - 铁 :router not rendering template

标签 javascript templates meteor render iron-router

我正在使用 iron:router 包开发 meteor 。 我的 javascript 文件包含:

Router.route('/', function () {
  this.render('home');
}, {
  name: 'home'
});

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

我的 html 文件包含:

<head>
  <title>test</title>
</head>

<body>
  <h1>Welcome to Meteor!</h1>

</body>

<template name="hello">
  <button>Click Me</button>
  <p>You've pressed the button {{counter}} times.</p>
</template>

<template name="home">
  <h2>Home</h2>
  <p>You are on the home screen.</p>
</template>

无论我写什么(localhost:3000/hellolocalhost:3000/),如 the tutorial 中指定的那样,无论如何它根本不会呈现任何模板。它只是显示标题“Welcome to Meteor!”就是这样。

当我写入任何其他未声明的地址时,例如 localhost:3000/abc,它会显示:

Welcome to Meteor! Oops, looks like there's no route on the client or the server for url: "http://localhost:3000/abc."

所以它肯定在 javascript 文件中做了一些正确的事情,因为它识别了它应该知道的模板,但是当写入正确的地址时,它仍然没有显示任何内容。

我尝试查看其他解决方案,检查包名称是“iron:router”而不是“iron-router”,以及其他解决方案,但没有任何效果。请帮助我...

编辑:根据要求,这里是项目的存储库 https://github.com/yokhen/test2

最佳答案

首先我必须添加 EJSON 包,因为 iron:router 没有看到它(虽然我在 Windows 上测试它,也许这就是我遇到这个问题的原因)

meteor add ejson 解决了

您的项目目录应如下所示:

enter image description here

路由.js

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

Router.route('/items');

test2.js

Template.items.helpers({

});

Template.items.events({

});

Template.Home.helpers({

});

Template.Home.events({

});

test2.html

<template name="Home">
    <h1>Simplest template home ever</h1>
</template>

<template name="items">
    <h1>Simplest home items template</h1>
</template>

关于javascript - 铁 :router not rendering template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32799670/

相关文章:

javascript - 使用 javascript 更改标记名

c++ - 通过模板发布 C++ Eigen::Matrix 类型

php - 将自定义类别添加到愿望 list 顶部链接

javascript - Angularjs:手动引导是否存在性能问题?

javascript - D3 - 将数据标签添加到简单的条形图中

javascript - 在 Laravel 中将 php var 传递给 javascript

c++ - 使用 ptr-ref 类型的模板特化和特化规则

javascript - Meteor 存放陨石包的位置

javascript - meteor : Cordova 和网站的不同(铁)路线

javascript - 如何在 Meteor-cordova 项目上添加应用程序链接