- Check out the current version of my project here
- Access the code for my project here
Background:
In my latest project, I am developing a blog using meteor and iron-router. The goal is to utilize a single controller for multiple "category pages" that filter a list of blog articles in the yield region.
The Problem:
One key issue I'm facing is that the article list does not refresh when the URL changes, meaning it lacks reactivity. Interestingly, when navigating back to the home page, the correct article list appears.
The Question:
I'm seeking guidance on how to update the article list dynamically when switching between different routes on the category route controller.
Example Code:
To explore the full codebase of this project, please visit this link.
Below is an excerpt from my Route Controller:
CategoryController = RouteController.extend({
action: function(){
this.render();
},
template: 'category',
data: function(){
return {category: this.params.category};
}
});
CategoryController.helpers({
articles: function(){
return Articles.find({category: this.params.category});
}
});
And here is the associated template it renders:
<template name='category'>
<div class="container">
<h2>{{category}}:</h2>
<ul>
{{#each articles}}
<li>
{{#linkTo route="article.show"}}
{{title}}
{{/linkTo}}
</li>
{{/each}}
</ul>
</div>
</template>
Resources/Updates:
- Take a look at this informative article on Meteor Reactivity and the Deps Package. While experimenting with
Deps.autorun
in various sections, it seems like this may not provide the solution needed. - Currently exploring methods to have different "category" routes inherit from the controller.