在Blaze升级后,pathFor参数不再有效

时间:2014-04-03 19:29:57

标签: meteor iron-router meteor-blaze

我更新流星0.7到0.8,铁路由器0.6.2到0.7.0并添加了火焰布局0.2.2。

以前我有使用两个参数的路径。剥离到它看起来像这样的基本部分:

{{#each users}}                                                                                                                                                                          
   <a href="{{pathFor 'template' _id=this._id fooParam=foo}}">link text</a>
{{/each}}

更新后,pathFor仅返回模板的url,没有对params进行任何操作。我还可以显示变量,一切都正确显示:

{{#each users}}
   {{this._id}} {{!displayed correctly in browser}}  
   {{foo}}      {{!displayed correctly in browser}}                                                                                                                            
   <a href="{{pathFor 'template' _id=this._id foo_param=foo}}">link text</a>
{{/each}}

如果我只是尝试使用带有_id set的数据上下文,那么结果没有变化:

{{#each users}}                                                                                                                            
   <a href="{{pathFor 'template'}}">link text</a>
{{/each}}

任何想法都将不胜感激!

2 个答案:

答案 0 :(得分:2)

来自iron-router的{​​{1}}回复:

  

{{pathFor}}和{{urlFor}}仍然适用于一些api更改:

     
      
  • {{pathFor'routeName'params = this query =“key = value&amp; key2 = value2”hash =“somehash”anotherparam =“anothervalue”}}
  •   
  • {{urlFor}}
  • 相同   

根据History.md(第41-47行)中的评论:

 /**
 * Example Use:
 *
 *  {{pathFor 'items' params=this}}
 *  {{pathFor 'items' id=5 query="view=all" hash="somehash"}}
 *  {{pathFor route='items' id=5 query="view=all" hash="somehash"}}
 */

换句话说,您的pathFor帮助器需要如下所示:

<a href="{{pathFor 'template' _id=this._id query="foo_param=foo"}}">link text</a>

希望有所帮助。

答案 1 :(得分:1)

fletch是正确的,因为我昨天修复了同样的事情。见https://github.com/EventedMind/iron-router/issues/580#issuecomment-39526280

对于每个路径,我在浏览器控制台中收到以下错误:

Exception in Meteor UI: TypeError: Cannot read property 'params' of undefined
at Object.processPathArgs (http://localhost:3000/packages/iron-router.js?a4167ac4d12a73891d8a9b8c57419a347da0ee12:2200:22)
at Object._.extend.pathFor (http://localhost:3000/packages/iron-router.js?a4167ac4d12a73891d8a9b8c57419a347da0ee12:2227:34)
at http://localhost:3000/packages/ui.js?b523ef986d3d39671bcb40319d0df8982acacfe8:2838:23
at Spacebars.call (http://localhost:3000/packages/spacebars.js?5d478ab1c940b6f5a88f78b8adc81a47f022da77:173:18)
at Spacebars.mustacheImpl (http://localhost:3000/packages/spacebars.js?5d478ab1c940b6f5a88f78b8adc81a47f022da77:110:25)
at Object.Spacebars.mustache (http://localhost:3000/packages/spacebars.js?5d478ab1c940b6f5a88f78b8adc81a47f022da77:114:39)
at HTML.A.href (http://localhost:3000/client/views/prayers/template.prayer_item.js?e15ce9378850d2ce553c8c60647642a543534557:58:30)
at http://localhost:3000/packages/htmljs.js?697b0dd0fbdd1f8984dffa3225121a9b7d0b8609:254:14
at callWithNoYieldsAllowed (http://localhost:3000/packages/deps.js?7afb832ce6e6c89421fa70dc066201f16f9b9105:74:5)
at _.extend._compute (http://localhost:3000/packages/deps.js?7afb832ce6e6c89421fa70dc066201f16f9b9105:212:7) 

我刚将{{pathFor'items'this}}更改为{{pathFor'items'params = this}}