State of nested routes in EmberJS

假如想象 提交于 2019-12-23 01:13:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!