简体   繁体   English

FlowRouter:Kadira触发页面加载

[英]FlowRouter:Kadira Trigger On Page Load

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

If that's the only feature you want, you might be interested in the zimme:active-route package on Atmosphere . 如果这是您想要的唯一功能,那么您可能会对Atmosphere上的zimme:active-route软件包感兴趣。 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). 否则,知道何时渲染是模板的事,而不是路由器的事,因此您需要将代码附加到模板事件(例如onCreated (假设您使用的是Blaze)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM