通过铁路由器发送数据上下文模板这是我的路由器:不能流星
Router.route('/cource/:courcePath', {
name: 'Cource_page',
template: 'Cource_page',
data() {
return Cources.find({ courcePath: this.params.courcePath });
}
});
模板:
<template name="Cource_page">
<div class="container">
{{#each cources}}
<h1>{{courceTitle}}</h1>
{{/each}}
</div>
</template>
和助手:
Template.Cource_page.helpers({
cources() {
let courcePath = this.courcePath;
console.log(courcePath);
return Cources.find({ courcePath: courcePath });
}
});
当我去到某个页面(例如http://localhost:3000/cource/my-new-cource),没有数据呈现,我在控制台中获得undefined
(模板h的输出elpers)。我究竟做错了什么?
PS:我建议你学习Flow-Router,它正在成为Meteor的事实上的路由器,并且更加灵活。我在Iron-Router上构建了自己的应用程序,并且在开始与Iron-Router发生问题时不得不重写很多内容(如随机重新渲染...)https://github.com/kadirahq/flow-router – MrE