【问题标题】:How can I assign active class to the current route link in ampersand.js?如何将活动类分配给 &ampersand.js 中的当前路由链接?
【发布时间】:2016-06-26 22:01:11
【问题描述】:

我有这些路线:

routes: {
   '': 'index',
   'lifestyle': 'lifestyle',
   'about': 'about'
},

index: function() {

},

lifestyle: function() {

},

about: function() { 

}

如何确定哪一个是活动路线,以便将“活动”类分配给相应的导航链接?

【问题讨论】:

    标签: javascript backbone.js ampersand ampersand.js


    【解决方案1】:

    最简单的方法是监听路由器发出的route 事件,并在它被触发时分配你的active 类。对于您的routes 定义:

    routes: {
       '': 'index',
       'lifestyle': 'lifestyle',
       'about': 'about'
    }
    

    您可以像这样收听route 事件:

    router.on("route", function(page, ...arguments) {
      //here 'page' can be 'index', 'lifestyle' or 'about'.
      //then you can save the 'page' in a variable or assign your 'active' class right away
    });
    

    还可以查看last paragraph of the documentation

    【讨论】:

      猜你喜欢
      • 2016-04-30
      • 1970-01-01
      • 2012-07-09
      • 1970-01-01
      • 1970-01-01
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      相关资源
      最近更新 更多