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