Joined July 2014
·
Posted to
No fuss active link states in Meteor
over 1 year
ago
This no longer works in Blaze layout because render isn't always called.
Instead, in index.js I've done this:
Template.layout.rendered = function() {
Template._setActiveLinks();
};
Template.setActiveLinks = function() {
var path, stem;
path = location.pathname;
if(location.pathname !== '/') {
$("a[href].active").removeClass('active');
$("a[href='" + path + "']").addClass('active');
stem = path.split('/')[1];
$('.navbar-nav > li.active').removeClass('active');
return $(".navbar-nav a[href^='/" + stem + "']").parent().addClass('active');
}
}
And then I call it from:
onBeforeAction: function(){
Template.setActiveLinks();
}
For every route, not ideal I'm sure...
Not sure why formatting is wanged on that comment...