我以前做过这样的事情如下:
pageDidChange: Ember.observer('currentPath', function() {
this.set('pageClassName', this.get('currentPath').replace(/[.]/g, '-'));
}),
然而,这不再有效,因为currentPath属性似乎已经消失。我也在EmberJS网站的API文档中找不到它。
我现在应该这样做吗?
答案 0 :(得分:0)
有多种访问当前路线的方法,
1)直接在hbs中
{{currentRouteName}}
2)在您的控制器中
this.get('router.currentPath');
3)从您的路线访问路由器信息
setupController: function(controller, model) {
this._super(controller, model);
let targetRoute = this._router._routerMicrolib.activeTransition.targetName;
controller.set('currentPath', targetRoute);
},
在您的模板中:
{{currentPath}}