我有这些路线:
routes: {
'': 'index',
'lifestyle': 'lifestyle',
'about': 'about'
},
index: function() {
},
lifestyle: function() {
},
about: function() {
}
如何确定哪一个是活动路由,以便我可以将"活动"类分配给相应的导航链接?
最简单的方法是侦听路由器发出的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
});
另请查看文档的最后一段