问题
I have a route structure like this:
this.resource('A',function(){
this.resource('B',function(){
this.route('C');
});
});
Is there a way I can check in A, which nested route of B is currently active?
For usability reasons I have a navigation in A, which also holds links for B.C and B.index But I only want to show one of those two links.
回答1:
The application controller has a property on it currentPath. You can use that to find out which path in the router you're currently on. It's the entire path, so it'd be A.B.C or A.B.index.
App.ColorsController = Ember.ArrayController.extend({
needs:'application',
atIndex: Em.computed.equal('controllers.application.currentPath', 'colors.index')
});
Example: http://emberjs.jsbin.com/nobima/2/edit
来源:https://stackoverflow.com/questions/26706232/state-of-nested-routes-in-emberjs