使用Meteor 0.9.3和iron:路由器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>
答案 0 :(得分:7)
这不是iron:router
布局应该如何工作的方式。
摆脱在体内明确包含布局:
{{! this is WRONG, remove the body tag altogether }}
<body>
{{> defaultLayout}}
</body>
您指定layoutTemplate
的地点位于RouteController
:
Router.route('/', function () {
this.render('home');
},{
layoutTemplate:"defaultLayout"
});
明确声明您的RouteController
通常是更好的设计模式。
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({
//
});
答案 1 :(得分:2)
好吧,就像你的错误说你错过了铁布局。
在lib/router.js
或您保存路由器代码的任何地方都可能看起来像这样:
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading'
});
所以相应的<template name="layout">
应该在那里。