Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript iron:路由器没有渲染模板_Javascript_Templates_Meteor_Render_Iron Router - Fatal编程技术网

Javascript iron:路由器没有渲染模板

Javascript iron:路由器没有渲染模板,javascript,templates,meteor,render,iron-router,Javascript,Templates,Meteor,Render,Iron Router,我正在使用“铁:路由器”软件包开发meteor。 我的javascript文件包含: Router.route('/', function () { this.render('home'); }, { name: 'home' }); Router.route('/hello', function () { this.render('hello'); }); <head> <title>test</title> </head>

我正在使用“铁:路由器”软件包开发meteor。 我的javascript文件包含:

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

Router.route('/hello', function () {
  this.render('hello');
});
<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>
我的html文件包含:

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

Router.route('/hello', function () {
  this.render('hello');
});
<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>

测试
欢迎来到流星!
点击我
您已按了{counter}}按钮次数

家 您在主屏幕上

无论我按照中的指定编写什么(
localhost:3000/hello
localhost:3000/
),无论它是什么都不会呈现任何模板。它只显示标题“欢迎来到Meteor!”就这样

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

欢迎来到流星!哎呀,看起来客户端或服务器上没有路由 url“”的服务器

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

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


编辑:根据要求,这里是项目的存储库

创建一个“lib”文件夹,并将代码放在其中

lib/router.js
你需要把
{{>yield}}
放在你的body标签里面

<body>
  <h1>Welcome to Meteor!</h1>
    {{> yield}} 
</body>

欢迎来到流星!
{{>产量}

还将向您展示如何设置layoutTemplate,该模板可用于在所有模板之间保持一致的布局。您将把{{>yield}放在布局模板内,并使用
路由器。配置
函数以在布局模板内生成其他模板。

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

meteor add ejson
解决了它

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

Routes.js test2.js test2.html

有史以来最简单的模板主页
最简单的主页项模板

它甚至看不到iron:router包,因为它显示的是基本模板(在
正文
标签中)。否则,如果是路由问题,您将看到类似于
whoops,route for。。。不存在
。你的routes.js文件在哪里?在lib目录中?@Sindis我刚刚添加了额外的信息。我的.js文件在项目文件夹中只保留html文件中的模板,删除主体和头部标记-现在显示什么?@Sindis是的,也尝试过,但没有显示任何内容。我可能会尝试一下MeteoBuzz的答案,但这需要几分钟的时间,希望它能起作用。MeteoBuzz的答案是关于布局的,我不认为这会有什么不同-也许用你已经做过的代码创建简单的github repo,我们会检查它。好吧,我正在尝试从简单到复杂。如果最简单的一行(
Router.route('/items');
)没有显示任何内容,我怎么能指望
Router.configure
{>yield}
为我工作?尽管如此,我还是尝试了,但它也没有显示任何内容。它仍然可以识别路由,但根本不显示任何模板。@Yokhen,在查看github之后,您必须在根级别创建一个“lib”文件夹,并将路由代码放在其中。我可以在哪里了解更多详细信息?我很惊讶我没有读到任何关于这方面的文章,或者完全没有读到。。U_UYeap,这里根本没有提到lib文件夹,尽管如此,我还是尝试了解决方案。我添加了一个lib文件夹,创建了一个“router.js”文件,并将所有的iron:router代码移到了那里,但没有任何更改。。。我想在github上展示这一点,但是提交的过程太复杂了…哇。我的英雄!是的,我也在使用Windows。不幸的是,在昨天把我的耳朵撕了这么多之后,我切换到了flow router。你们认为我应该改回去还是坚持使用它?我并没有使用flow router,但我听到了一些关于它的好的选择,也有一些负面的选择。你应该检查文档,也许继续阅读,然后使用更适合你的API。我一直在尝试为这两种API寻找API,但我似乎找不到任何API,只有教程。编辑:没关系,找到了流量路由器,但还是要找到铁路由器。
<template name="Home">
    <h1>Simplest template home ever</h1>
</template>

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