I'm trying to make a link stay 'active' on multiple routes, such as /#/users and /#/user.
Any ideas?
You can reopen Ember's LinkView and do something like this (allows currentWhen to contain space delimited values)
Ember.LinkView.reopen({
active: function() {
// we allow link-to's currentWhen to specify multiple routes
// so we need to check each one of them
var loadedParams = Ember.get(this, 'loadedParams');
var currentWhen = this['current-when'] || this.currentWhen;
currentWhen = currentWhen || (loadedParams && loadedParams.targetRouteName);
if (currentWhen && currentWhen.indexOf(' ') >= 0) {
var currents = currentWhen.split(' ');
router = Ember.get(this, 'router');
for (var i = 0; i < currents.length; i++) {
var isActive = router.isActive.apply(router, [currents[i]]);
if (isActive)
return isActive;
}
return false;
}
return this._super();
}.property('resolvedParams', 'routerArgs')
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With