FlowRouter:Kadira Trigger On Page Load

时间:2022-12-04 20:42:10

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.

我在页面加载时在导航栏上添加活动类时遇到问题。单击页面时,triggerEnters可以工作,但是当页面加载时我也想要它。

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');
}

1 个解决方案

#1


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).

如果这是你想要的唯一功能,你可能会对atmosphere上的zimme:active-route包感兴趣。否则,知道何时呈现它是模板的业务,而不是路由器,因此您需要将代码附加到模板事件(例如onCreated)(假设您正在使用Blaze)。

#1


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).

如果这是你想要的唯一功能,你可能会对atmosphere上的zimme:active-route包感兴趣。否则,知道何时呈现它是模板的业务,而不是路由器,因此您需要将代码附加到模板事件(例如onCreated)(假设您正在使用Blaze)。