我的问题是我必须创建帖子,但有一次我想带我到显示帖子的页面我创建了我的网址
midomain.com / post / id
流星并使用铁路由器,但当我发布遗骸永远加载并且从未向我显示页面时midomain.com / post / id
我也在手动进行订阅和发布...
配置铁路由器
Router.map(function(){
this.route('showSnippet', {
path:'/snippets/:_id',
controller:'SnippetShowController',
action:'show'
});
this.route('home', {
path:'/',
template:'form'
})
});
SnippetShowController = RouteController.extend({
before: function () {
var _id = this.params._id;
if(App.subs.snippet)
App.subs.snippet.stop();
App.subs.snippet = Meteor.subscribe('snippet', _id);
},
data: function () {
return Snippets.findOne({_id: this.params._id});
},
run: function () {
this.render('showSnippet');
}
});
订阅
App = {
subs: {
snippets: Meteor.subscribe('snippets')
}
};
出版物
Meteor.publish('snippet', function (id) {
return Snippets.find({_id: id});
});
我想澄清一下'帖子'我的意思是我的名字叫'片段' 单击“提交”表单后执行验证后
Router.go ('showSnippet');`
谢谢!
对不起我的英语,但我使用谷歌翻译
答案 0 :(得分:1)
替换
before: function () {
var _id = this.params._id;
if(App.subs.snippet)
App.subs.snippet.stop();
App.subs.snippet = Meteor.subscribe('snippet', _id);
}
带
before: function () {
var _id = this.params._id;
this.subscribe('snippet', _id).wait();
}
或
waitOn: function () {
var _id = this.params._id;
return Meteor.subscribe('snippet', _id);
}