How Do You Render Multiple Templates With One Route Controller Using Iron-router?
URL to current version of my project Here is the code for my project Background: I am making a blog using meteor and iron-router. I want to use a single controller for several
Solution 1:
The article list does not change because the Template helper is not using a reactive data source. You may use the RouteController.getParams
method to establish a reactive dependency on route parameters as shown below.
CategoryController.helpers({
articles: function(){
var controller = this;
var params = controller.getParams();
return Articles.find({category: params.category});
}
});
From Iron Router documentation:
Note: If you want to rerun a function when the hash changes you can do this:
// get a handle for the controller. // in a template helper this would be // var controller = Iron.controller(); var controller = this; // reactive getParams method which will invalidate the comp if any part of the params change // including the hash. var params = controller.getParams();
By default the router will follow normal browser behavior. If you click a link with a hash frag it will scroll to an element with that id. If you want to use controller.getParams() you can put that in either your own autorun if you want to do something procedural, or in a helper.
Post a Comment for "How Do You Render Multiple Templates With One Route Controller Using Iron-router?"