簡體   English   中英

Meteor.js Iron Routing:_id動態路由混亂

[英]Meteor.js Iron Routing :_id dynamic route confusion

我目前正在通過“您的第二顆流星應用程序”進行工作,到目前為止一直很喜歡。 我創建的所有內容都可以使用,但是我不明白為什么以下內容可以使用,但是最后的代碼卻不起作用。

模板

<template name="list">
  <ul>
    {{#each list}}
      <li><a href="/list/{{_id}}">{{name}}</a></li>
    {{/each}}
  </ul>
</template>

<template name="listPage">
  <h2>Tasks: {{name}}</h2>
</template>

路線

Router.route('/list/:_id', {
  template: 'listPage',
  data: function(){
    var currentList = this.params._id;
    return Lists.findOne({_id: currentList});
  }
});

這給出了預期的結果。 但是,我很好奇以下內容為什么不起作用,因為它似乎傳遞了完全相同的東西。 與以下各項的唯一區別是:

  • 將Router.route('lists /:_ id')更改為Router.route('lists / randomParm')
  • this.params._id到this.params.randomParm

模板

<template name="list">
  <ul>
    {{#each list}}
      <li><a href="/list/{{_id}}">{{name}}</a></li>
    {{/each}}
  </ul>
</template>

<template name="listPage">
  <h2>Tasks: {{name}}</h2>
</template>

路線

Router.route('/list/randomParm', {
  template: 'listPage',
  data: function(){
    var currentList = this.params.randomParm;
    return Lists.findOne({_id: currentList});
  }
});

我收到的消息是:

糟糕,看來客戶端或服務器上的URL沒有路由:“ http:// localhost:3000 / list / TGM9dbRRtspyJy7AR”

:_id和randomParm是否保持相同的值? 來自HTML鏈接的列表項的ID是否正在傳遞到路由URL,並用於進行mongo調用? 當我點擊相同的路由URL時,我不太了解:_id和randomParm有何不同。

參數設置為:

所以你的路線是

Router.route('/list/:randomParm', {

如果此參數是可選的,則離開?

Router.route('/list/:randomParm?', {

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM