通過鐵路由器發送數據上下文模板這是我的路由器:不能流星
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