如果您想在组件或控制器中获取当前路由,您可以注入路由服务 ( routing: Ember.inject.service('-routing')
)
(更多)并使用:
this.get('routing.currentRouteName')
或者this.get('routing.currentPath')
带有组件和计算属性的示例:
import Ember from 'ember';
export default Ember.Component.extend({
routing: Ember.inject.service('-routing'),
checkMyRouteName: Ember.computed('routing.currentRouteName', function() {
return this.get('routing.currentRouteName');
})
})
带有控制器和计算属性的示例:
import Ember from 'ember';
export default Ember.Controller.extend({
routing: Ember.inject.service('-routing'),
checkMyRouteName: Ember.computed('routing.currentRouteName', function() {
return this.get('routing.currentRouteName');
})
})
您只需要路线中的当前路线this.routeName
路线示例:
import Ember from 'ember';
export default Ember.Route.extend({
checkMyRouteName() {
return this.routeName;
}
})