【发布时间】:2015-12-24 07:38:45
【问题描述】:
我正在使用 iron:router 包开发流星。 我的 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/hello 或localhost:3000/),都按照the tutorial 的规定,无论如何它都不会呈现任何模板。它只是显示标题“Welcome to Meteor!”就是这样。
当我写任何其他未声明的地址(例如localhost:3000/abc)时,它会向我显示:
欢迎来到流星!糟糕,客户端上似乎没有路由,或者 url 的服务器:“http://localhost:3000/abc.”
所以它肯定在 javascript 文件中做了一些正确的事情,因为它可以识别它应该知道的模板,但是在写入正确的地址时,它仍然什么都不显示。
我尝试查看其他解决方案,检查包名称是否为“iron:router”而不是“iron-router”,以及其他解决方案,但没有任何效果。请帮帮我...
编辑:根据要求,这里是项目https://github.com/yokhen/test2的存储库
【问题讨论】:
-
它甚至没有看到 iron:router 包,因为它显示了基本模板(在
body标签中)。否则,如果是路由问题,您会看到类似Whooops, route for ... doesn't exist的内容。你的路由 .js 文件在哪里?在 lib 目录下? -
@Sindis 我刚刚添加了额外的信息。我的 .js 文件在项目文件夹中
-
在您的 html 文件中只保留模板,删除 body 和 head 标签 - 它现在显示什么?
-
@Sindis 是的,也尝试过,但没有任何结果。我可能会尝试一下 meteorBuzz 的答案,但这需要我几分钟,希望它能奏效。
-
meteorBuzz 的答案是关于布局的,我认为这不会产生影响——也许可以使用您已经完成的代码创建简单的 github 存储库,我们会检查它
标签: javascript templates meteor render iron-router