Meteor: There is no route for the path error. how to access SINGLE article within a nested object

妖精的绣舞 提交于 2019-12-12 03:39:11

问题


I have an array of 10 objects 'categories' and each category has sub objects such as posts within that category. This is how it looks.

I access the category list like this.

<template name="CategoriesMain">
  {{#each articles}}
    <li>
      <a href="/unfiltered/{{_id}}"><h2>{{name}}</h2></a>
    </li>
  {{/each}}
</ul>
</template>

this link

<a href="/unfiltered/{{_id}}"><h2>{{name}}</h2></a>

accesses the 'posts' list within the category which looks like this

<template name="CategoriesSingle">

<h1>This is a test</h1>
<ul>
  {{#each articles}}
  {{#each posts}}
    <li>
      <a href="/catsingle/{{_id}}"><h2>{{title}}</h2></a>
    </li>
    {{/each}}
  {{/each}}
</ul>
</template>

this link is supposed to target the SINGLE POST from the post list within the category

<a href="/catsingle/{{_id}}"><h2>{{title}}</h2></a>

PROBLEM:

I get the error: There is no route for the path: /catsingle/ when ever i try to access the SINGLE POST

even though i have it in my routes.js like this

FlowRouter.route('/catsingle/:_id', {
    name: 'catsingle',
    action() {
        BlazeLayout.render("AppLayout", {main: "CategoryArticleSingle"});
    }
});

the template helper looks like this

  Template.CategoryArticleSingle.helpers({
      articles: function () {
        var id = FlowRouter.getParam('_id')
        return CategoryCollection.findOne({_id: id});
      }
    });

How can I successfully the single post within a category?


回答1:


Your posts array doesn't have an _id key, it has an ID key.

Try:

<a href="/catsingle/{{ID}}"><h2>{{title}}</h2></a>


来源:https://stackoverflow.com/questions/37902133/meteor-there-is-no-route-for-the-path-error-how-to-access-single-article-withi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!