用这个 this.controllerFor('application').get('currentRouteName');
实际上,您不需要自己申请活动课程.一个link-to助手将做给你.
看到这里:
{{link-to}}当应用程序的当前路由与提供的routeName匹配时,将应用CSS类名"active".例如,如果应用程序的当前路线是"photoGallery.recent",则以下使用{{link-to}}:
{{#link-to 'photoGallery.recent'}}
Great Hamster Photos
{{/link-to}}
Run Code Online (Sandbox Code Playgroud)
会导致
<a href="/hamster-photos/this-week" class="active">
Great Hamster Photos
</a>
Run Code Online (Sandbox Code Playgroud)
对于 Ember 2,您可以从控制器尝试:
appController: Ember.inject.controller('application'),
currentRouteName: Ember.computed.reads('appController.currentRouteName')
Run Code Online (Sandbox Code Playgroud)
然后你可以将它传递给组件。
| 归档时间: |
|
| 查看次数: |
15862 次 |
| 最近记录: |