user1950110
user1950110

Reputation: 1

pathFor cannot find route - Iron Router & Meteor

Iron Router cannot find a path that I'm pretty sure is defined correctly. The path name shows up as valid and exists in my meteor shell, but it returns as "undefined" in my Chrome console. Here's the template declaration:

<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>

And here's the route declaration:

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');
  }
});

There are no helpers operating on the vidPreview template. The data context is that of an individual Video object, and this template gets placed multiple times into a parent template. Help is greatly appreciated.

Upvotes: 0

Views: 223

Answers (2)

JeremyK
JeremyK

Reputation: 3240

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

Try:

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

Upvotes: 0

Michel Floyd
Michel Floyd

Reputation: 20256

I thought the route name parameter in pathFor was positional, i.e.

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

Upvotes: 0

Related Questions