【发布时间】:2015-01-28 18:21:13
【问题描述】:
我在 Iron-Router 中设置了两条路由:“home”(所有帖子的分页列表)和“doc”(详细视图)。主页加载得很好,但只有在以前查看过主页时才能加载详细视图。否则它将呈现为空 - 并且不能用作永久链接。
这将始终加载: http://localhost:3000/
只有在之前查看过“home”时才会加载: http://localhost:3000/doc/tZFawq8cgf43hZBaJ
路线:
Router.map(function() {
this.route('home', {
path: '/'
});
this.route('doc', {
path: '/doc/:_id',
data: function() {
return MyPix.findOne({_id: this.params._id});
}
});
});
文档模板:
<template name="doc">
<h1>{{this.name}}</h1>
<img src="{{ this.url store='OriginalRetinaPix' }}" width="{{ this.metadata.width }}" height="{{ this.metadata.height }}" />
</template>
发布/订阅:
Meteor.publish('MyPix', function(cursor) {
Counts.publish(this, 'numberOfPosts', MyPix.find(), { noReady: true });
return MyPix.find({}, {sort: {uploadedAt: -1}, limit: 4, skip: cursor});
});
if(Meteor.isClient) {
Session.setDefault('docCursor', 0);
console.log('docCursor: ' + Session.get('docCursor'));
Meteor.autorun(function(){
Meteor.subscribe('MyPix', Session.get('docCursor'));
})
}
顺便说一句:GitHub上的项目
【问题讨论】:
标签: javascript meteor iron-router