I’m not doing anything freaky here, I thought it would be easy to implement this sort of things so I’m positive I’m doing something wrong or my question wasn’t clear before. Thanks!
Ok here’s a solution based on my previous but it actually uses Blaze. I’ll post all of the files so you can run it as well. You don’t even need the active-route package
Since there is not getPath from the API, I had to use FlowRouter.getRouteName to trigger a re-render as FlowRouter.current() is not reactive.
@dgreensp@sashko Blaze can still rival React when you think modular !
FlowRouter.route('/about', {
action: function(params, queryParams) {
console.log('/about', params, queryParams);
}
});
FlowRouter.route('/', {
action: function(params, queryParams) {
console.log('/home', params, queryParams);
}
});
if (Meteor.isClient) {
Template.NavItem.helpers({
activeClass: function () {
// make this re-render on change, even if we don't use var
var routeName = FlowRouter.getRouteName();
if (FlowRouter.current().path === this.href) {
return 'active';
}
}
});
}
But for a top level route, you can do {{isActiveRoute name=name}}
To be frank, I find zimme active-route package lacking support for dynamically created nested routes; ie, you cannot (or I don’t know how) catch a /products/:_id/view route structure when you want to catch a “specific” product ID. But then, you can perhaps hack away using its regex property. But then you need some way to build the regex dynamically and for that, you need to be able to write javascript expressions within the handlebar helpers, and I guess that’s not supported.
For those, I guess the best bet is to use official FlowRouter API’s just like @SkinnyGeek1010 explained.
I definitely agree, most examples are not the best and make use of session.
I never use the session object, i mostly only keep states internally in the template using my frozeman:template-var and i make the templates in a way, that i pass the data in. This way i get nice reusable components and they save me a lot of refactor work, as i only have to go to one place
but for this, it might be cleaner to name the route which handles showing a specific product to like ‘showProduct’ and then use {{isActiveRoute 'showProduct'}} with this it would work for all _id’s.
I’ve actually thought about adding params attribute or something to support matching against route with specific parameters but as you can match against path I’ve thought that might have been enough.