pathFor找不到路由 - Iron Router&流星

时间:2015-09-18 20:23:17

标签: javascript meteor routing iron-router

铁路由器无法找到我确定无法正确定义的路径。路径名称显示为有效且存在于我的meteor shell中,但它返回为" undefined"在我的Chrome控制台中。这是模板声明:

<template name="vidPreview">
<div class="videoPreview">
    <h2>{{title}}</h2>
    <a href="{{pathFor route='singleVideo' _id=this._id }}">Play</a>
    <p>Created At: {{createdAt}}</p>
    {{#if isLive}}
        <p>LIVE</p>
    {{/if}}
    <p>Viewers: {{uniqueViewers}}</p>
    <p>Views: {{views}}</p>
    <p>Location: {{location}}</p>
    <ul>
        {{#each genres}}
            <li><p>{{this}}</p></li>
        {{/each}}
    </ul>
    <p>Created by: {{creator}}</p>
</div>
</template>

以下是路线声明:

Router.route('/video/:_id',{
  name: 'singleVideo',
  template: 'singleVideo',
  layoutTemplate: 'singleVideo',
  data: function(){
    var currentVideo = this.params._id;
    return Videos.findOne({ _id: currentVideo });
  },
  action: function(){
    this.render('singleVideo');
  }
});

vidPreview模板上没有帮助程序。数据上下文是单个Video对象的上下文,此模板多次放入父模板中。非常感谢帮助。

2 个答案:

答案 0 :(得分:0)

我认为pathFor中的路由名称参数是位置的,即

{{pathFor 'singleVideo' _id=this._id }}

答案 1 :(得分:0)

"We can pass data, query and hash options to the pathFor helper."

尝试:

{{pathFor route='singleVideo' data={ _id: this._id} }}