我有以下几条路线:
routes: {
'': 'index',
'lifestyle': 'lifestyle',
'about': 'about'
},
index: function() {
},
lifestyle: function() {
},
about: function() {
}我如何确定哪一个是活动路由,以便我可以将‘活动’类分配给相应的nav链路?
发布于 2016-03-12 06:16:57
最简单的方法是侦听路由器发出的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
});https://stackoverflow.com/questions/35943934
复制相似问题