【问题标题】:How do I create separate template HTML files using Meteor Iron Router如何使用 Meteor Iron Router 创建单独的模板 HTML 文件
【发布时间】:2016-01-02 15:51:52
【问题描述】:

我有三个文件夹

客户

路由器

服务器

client 文件夹中还有一个名为 views 的文件夹,其中包含一个名为 layout.htmlhome.html 和 login.html

router 文件夹中有一个带有

的 router.js 文件
Router.configure({
  layoutTemplate: "Layout"
});

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

Router.route( "/login", function(){
  this.render( "Login" );
});

在我的 layout.html 文件中

<template name="Layout">
  <h1>Hello Layout</h1>
  {{ > yield }}
</template>

hello Layout 渲染得很好,但是找不到 home 模板。

如果我在 layout.html 中包含所有模板,则路由工作 4.0。

如何正确管理路由,以便每个模板都可以保留在自己的文件中?

更新 这是其他各自的模板

<template name="Home">
  <h1>This Is Home</h1>
</template>

and

<template name="Login">
  <h1>This Is Login</h1>
</template>

更新 2

我也在尝试使用meteor-angular,它希望html文件是name.ng.html。

从文件名中删除 ng 以使其与我上面描述的内容相匹配,并且一切正常。我会把这个留在这里,以防其他人遇到这个问题。

【问题讨论】:

  • 可以分享主页模板吗?
  • 啊,我忘了文件名是 home.ng.html,因为我也在尝试使用流星角。删除 ng 和路由工作。

标签: javascript meteor url-routing iron-router


【解决方案1】:

几天前我遇到了类似的问题。

如果您使用的是 Meteor 1.2 版,可能由于以下问题而无法正常工作:

https://github.com/iron-meteor/iron-middleware-stack/pull/7

您可以通过检查是否遇到异常来确认它:

Exception in callback of async function: ReferenceError: EJSON is not defined

所以虽然他们不更新包来修复它,但添加“ejson”包:

meteor add ejson

之后,它应该可以工作了。

【讨论】:

    猜你喜欢
    • 2015-08-31
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 2015-06-09
    • 2014-01-16
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    相关资源
    最近更新 更多