[英]How do I create separate template HTML files using Meteor Iron Router
I have three folders 我有三个文件夹
client 客户
router 路由器
server 服务器
In the client folder there is another folder called views which contain a file called layout.html , home.html , and login.html . 在client文件夹中,还有一个名为views的文件夹,其中包含一个名为layout.html , home.html和login.html的文件 。
In router folder there is a router.js file with 在router文件夹中有一个router.js文件,其中
Router.configure({
layoutTemplate: "Layout"
});
Router.route( "/", function(){
this.render( "Home" );
});
Router.route( "/login", function(){
this.render( "Login" );
});
In the layout.html file I have 在layout.html文件中
<template name="Layout">
<h1>Hello Layout</h1>
{{ > yield }}
</template>
hello Layout renders just fine, but the home template is not found. 你好布局渲染很好,但是没有找到主模板。
If I include all templates in the layout.html then routing works 4.0. 如果我将所有模板都包含在layout.html中,则路由工作于4.0。
How do I manage the routes correctly so that each template can remain in its own file? 如何正确管理路由,以便每个模板都可以保留在自己的文件中?
UPDATE Here are the other respective templates 更新这是其他各自的模板
<template name="Home">
<h1>This Is Home</h1>
</template>
and
<template name="Login">
<h1>This Is Login</h1>
</template>
UPDATE 2 更新2
I am also trying to use meteor-angular, which wants html files to be name.ng.html. 我也在尝试使用流星角,它希望html文件为name.ng.html。
Removing the ng from the file name so that it matched what I described above, and it all works again. 从文件名中删除ng ,使其与我上面所述的匹配,并且所有这些都可以再次使用。 I'll leave this here in case anyone else runs into this. 如果有人遇到这个问题,我会留在这里。
I faced a similar problem a few days ago. 几天前我遇到了类似的问题。
If you are using Meteor version 1.2, probably it is not working due to the following problem: 如果您使用的是Meteor 1.2版,则可能由于以下问题而无法正常工作:
https://github.com/iron-meteor/iron-middleware-stack/pull/7 https://github.com/iron-meteor/iron-middleware-stack/pull/7
You can confirm it by checking if you are getting an exception like : 您可以通过检查是否遇到异常来确认它:
Exception in callback of async function: ReferenceError: EJSON is not defined
So while they don't update the package to fix it, add the 'ejson' package: 因此,尽管他们不更新软件包来修复它,但添加“ ejson”软件包:
meteor add ejson
After it, it should work. 之后,它应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.