meteor - Uncaught Error : No Iron. 布局已找到,因此您无法使用 yield

标签 meteor iron-router

使用 Meteor 0.9.3 和 iron:router 1.0.0-pre2,即使安装了 iron:layout,此错误也会显示在控制台上,见下文:

willems-mini:iron willem$ meteor add iron:router@=1.0.0-pre2
added iron:location at version 1.0.0-pre2
added iron:dynamic-template at version 1.0.0-pre2
added iron:router at version 1.0.0-pre2
added iron:layout at version 1.0.0-pre2
added iron:middleware-stack at version 1.0.0-pre2
added iron:url at version 1.0.0-pre2
added iron:controller at version 1.0.0-pre2
added iron:core at version 1.0.0-pre2

iron:router: Routing specifically designed for Meteor

没有其他包,只有meteor 的默认值:
willems-mini:iron willem$ meteor list
autopublish      1.0.0  Publish the entire database to all clients
insecure         1.0.0  Allow all database writes by default
iron:router      1.0.0-pre2  Routing specifically designed for Meteor
meteor-platform  1.1.1  Include a standard set of Meteor packages in your app

我正在尝试运行一个非常简单的应用程序:

1个javascript文件:
Router.route('/', function () {
    this.render('home');
});

if (Meteor.isClient) {
    Template.home.events({
        'click button': function () {
            console.log('click!');
        }
    });
}

和 1 个 html 文件:
<head>
    <title>iron router test</title>
</head>

<body>
    {{> defaultLayout}}
</body>


<template name="defaultLayout">
    <header>
        {{> yield "header"}}
    </header>

    <article>
        {{> yield}}
    </article>

    <footer>
        {{> yield "footer"}}
    </footer>
</template>


<template name="home">
    {{#contentFor "header"}}
        <button>click header</button>
    {{/contentFor}}

    <button>click</button>

    {{#contentFor "footer"}}
        <button>click footer</button>
    {{/contentFor}}
</template>

最佳答案

这不是怎么回事iron:router布局应该可以工作。

摆脱你在 body 中显式包含的布局:

{{! this is WRONG, remove the body tag altogether }}
<body>
    {{> defaultLayout}}
</body>

您指定 layoutTemplate 的地方在 RouteController :
Router.route('/', function () {
  this.render('home');
},{
 layoutTemplate:"defaultLayout" 
});

明确声明您的 RouteController s 通常是一种更好的设计模式。
lib/router.js
Router.route("/",{
  // give the route a name so it figures out itself to use :
  // - HomeController
  // - a template name "home"
  name:"home"
});
lib/controllers/lib/default-layout.js
DefaultLayoutController=RouteController.extend({
  layoutTemplate:"defaultLayout"
});
lib/controllers/home.js
HomeController=DefaultLayoutController.extend({
  //
});

关于meteor - Uncaught Error : No Iron. 布局已找到,因此您无法使用 yield,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26121109/

相关文章:

caching - Meteor:后台加载所有页面资源

node.js - 使用 Node youtube-dl和MeteorJS保存视频文件

javascript - Meteor 订阅事件/渲染

Meteor js 作为前端,后端有什么用?

meteor + react : Server side routes?

node.js - Meteor:如何将大文件流式传输和解析为异步 Node 函数?

javascript - 带有iron-router的meteorjs动态路线图

javascript - 在 Meteor.js 中基于 URL 发布集合

meteor - 如何正确使用iron-router的waitOn路由选项?

javascript - 铁路由器: access route data in router function