在 Meteor 1.2 上的 Iron Router 布局有问题
Having problems with layouts in Iron Router on Meteor 1.2
我刚刚将我的 Meteor 应用程序更新为 Meteor v.1.2.0.2 和 Iron Router v.1.0.12。 Iron Router 不断在客户端返回此错误:Couldn't find a template named "layout" or "layout". Are you sure you defined it?
。除了这个错误,什么都没有呈现。这是我的 routes.js 文件:
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading'
});
Router.route('/', function() {
if (this.ready) {
this.render();
}
else {
this.render('loading');
}
},
{ name: 'main' } );
Router.route('/new/story', { name: 'newStory' } );
Router.route('/story/:_id', { name: 'viewStory', data: function() {
return Stories.findOne(this.params._id);
},
waitOn: function () {
return [Meteor.subscribe("story", this.params._id), Meteor.subscribe("seeds", this.params._id)];
},
onBeforeAction: function() {
var document = Stories.find({ _id: this.params._id }).fetch();
if ($.inArray(Meteor.user()._id, document[0].contributors) === -1) {
this.render('addSeed');
}
else {
this.next();
}
} } );
Router.route('/stories', { name: 'viewStories',
waitOn: function() {
Meteor.subscribe("stories");
}
});
Router.route('/story/:_id/new/seed', { name: 'addSeed', data: function() {
return Seeds.findOne(this.params._id);
}} );
Router.route('/logout', function() {
Meteor.logout();
Router.go("main");
});
布局模板如下所示:
<template name="layout">
{{> nav}}
{{> yield}}
</template>
我不明白哪里出了问题。请帮忙!
确保你有 ejson 包。如果缺少它,请使用 meteor 命令添加它:
meteor add ejson
确保你也有这个包列表:
meteor-base # Packages every Meteor app needs to have
mobile-experience # Packages for a great mobile UX
mongo # The database Meteor supports right now
blaze-html-templates # Compile .html files into Meteor Blaze views
session # Client-side reactive dictionary for your app
jquery # Helpful client-side library
tracker # Meteor's client-side reactive programming library
standard-minifiers # JS/CSS minifiers run for production mode
es5-shim # ECMAScript 5 compatibility for older browsers.
ecmascript # Enable ECMAScript2015+ syntax in app code
autopublish # Publish all data to the clients (for prototyping)
insecure # Allow all DB writes from clients (for prototyping)
iron:router
ejson
更新到 Meteor v.1.2 后我遇到了同样的错误。
事实证明问题出在实现包上。从 0.97.1
回滚到 0.97.0
版本的 materialize packcage 对我有用。
我刚刚将我的 Meteor 应用程序更新为 Meteor v.1.2.0.2 和 Iron Router v.1.0.12。 Iron Router 不断在客户端返回此错误:Couldn't find a template named "layout" or "layout". Are you sure you defined it?
。除了这个错误,什么都没有呈现。这是我的 routes.js 文件:
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading'
});
Router.route('/', function() {
if (this.ready) {
this.render();
}
else {
this.render('loading');
}
},
{ name: 'main' } );
Router.route('/new/story', { name: 'newStory' } );
Router.route('/story/:_id', { name: 'viewStory', data: function() {
return Stories.findOne(this.params._id);
},
waitOn: function () {
return [Meteor.subscribe("story", this.params._id), Meteor.subscribe("seeds", this.params._id)];
},
onBeforeAction: function() {
var document = Stories.find({ _id: this.params._id }).fetch();
if ($.inArray(Meteor.user()._id, document[0].contributors) === -1) {
this.render('addSeed');
}
else {
this.next();
}
} } );
Router.route('/stories', { name: 'viewStories',
waitOn: function() {
Meteor.subscribe("stories");
}
});
Router.route('/story/:_id/new/seed', { name: 'addSeed', data: function() {
return Seeds.findOne(this.params._id);
}} );
Router.route('/logout', function() {
Meteor.logout();
Router.go("main");
});
布局模板如下所示:
<template name="layout">
{{> nav}}
{{> yield}}
</template>
我不明白哪里出了问题。请帮忙!
确保你有 ejson 包。如果缺少它,请使用 meteor 命令添加它:
meteor add ejson
确保你也有这个包列表:
meteor-base # Packages every Meteor app needs to have
mobile-experience # Packages for a great mobile UX
mongo # The database Meteor supports right now
blaze-html-templates # Compile .html files into Meteor Blaze views
session # Client-side reactive dictionary for your app
jquery # Helpful client-side library
tracker # Meteor's client-side reactive programming library
standard-minifiers # JS/CSS minifiers run for production mode
es5-shim # ECMAScript 5 compatibility for older browsers.
ecmascript # Enable ECMAScript2015+ syntax in app code
autopublish # Publish all data to the clients (for prototyping)
insecure # Allow all DB writes from clients (for prototyping)
iron:router
ejson
更新到 Meteor v.1.2 后我遇到了同样的错误。
事实证明问题出在实现包上。从 0.97.1
回滚到 0.97.0
版本的 materialize packcage 对我有用。