2
假设我的应用绑定到window.App
: 我可以得到它的路由器App.__container__.lookup("router:main")
。如何获取当前路由名称?
如何访问当前路线?具体而言,我想获得其属性routeName
。
假设我的应用绑定到window.App
: 我可以得到它的路由器App.__container__.lookup("router:main")
。如何获取当前路由名称?
如何访问当前路线?具体而言,我想获得其属性routeName
。
它存在一个名为currentPath
的属性,它是应用程序当前状态的一个计算别名。为了得到当前routeName
这是你可以做这样的事情同样的事情:
App = Ember,Application.create({
currentPath: ''
});
ApplicationController : Ember.Controller.extend({
currentPathDidChange: function() {
App.set('currentPath', this.get('currentPath'));
}.observes('currentPath')
});
,然后用从任何地方访问它:
App.get('currentPath');
用于为currentPath
房产的更多信息,请参见here。
另外值得一提的是,您可以启用标志LOG_TRANSITIONS
为true,将当前路径名称在您的浏览器控制台的每个应用程序更改状态/路由时登录:
App = Ember.Application.create({
LOG_TRANSITION: true
});
注意 使用此App.__container__.lookup("router:main")
仅用于调试目的,因为它是一个内部API。
希望它有帮助。
我正在使用'App .__ container __。lookup'来修复Ember核心中的错误,因此我无法扩展应用程序控制器。我可以在哪里找到“currentState”?它不是“App”或“Router”的属性。 – chrmod
链接如果非常有帮助,谢谢。但如何从'App'访问'StateManager'? – chrmod
'StateManager'用于路由器的以前版本,现在在* v2 *中,路由器自己的工作是路由等。ApplicationController上的'currentPath'属性在这里处理:https:// github。 com/emberjs/ember.js/blob/v1.0.0-rc.5/packages/ember-routing/lib/system/router.js#L75 – intuitivepixel