【问题标题】:pathFor cannot find route - Iron Router & MeteorpathFor 找不到路线 - Iron Router & Meteor
【发布时间】:2015-12-16 02:24:12
【问题描述】:

Iron Router 找不到我很确定定义正确的路径。路径名显示为有效并且存在于我的流星外壳中,但它在我的 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 对象的数据上下文,并且此模板被多次放置到父模板中。非常感谢您的帮助。

【问题讨论】:

  • 你在哪里定义的路线?你确定它在客户端可用吗?

标签: javascript meteor routing iron-router


【解决方案1】:

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

试试:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-12
      • 2015-04-05
      • 2016-03-25
      • 2018-11-21
      • 2016-07-31
      相关资源
      最近更新 更多