0

I am having a problem with adding the active class on my navbar when the page load. The triggerEnters works when I click the page, but I also want it when the page loads.

Here's my code:

var headerRoutes = FlowRouter.group({
    triggersEnter: [activePage]
});

function activePage(){

    var selector = '.nav li a[href="' + FlowRouter.current().path + '"]';
    $('.navbar-nav li.active').removeClass('active');
    $(selector).parent("li").addClass('active');
}
Sydney Loteria
  • 10,171
  • 19
  • 59
  • 73

1 Answers1

0

If that's the only feature you want, you might be interested in the zimme:active-route package on Atmosphere. Otherwise, it's the template's business, not the router's, to know when it was rendered, so you'll need to attach your code to a template event such as onCreated (assuming you're using Blaze).

Guilherme
  • 608
  • 1
  • 6
  • 13