gpt4 book ai didi

ember.js - 如何获取当前的routeName?

转载 作者:行者123 更新时间:2023-12-02 19:29:36 30 4
gpt4 key购买 nike

假设我的应用程序绑定(bind)到 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');

参见here有关 currentPath 属性的更多信息。

还值得一提的是,您可以将 LOG_TRANSITIONS 标志启用为 true,以便在应用程序每次更改状态/路由时将当前路由名称记录在浏览器控制台中:

App = Ember.Application.create({
LOG_TRANSITION: true
});

注意App.__container__.lookup("router:main") 仅用于调试目的,因为它是内部 API。

希望有帮助。

关于ember.js - 如何获取当前的routeName?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17244353/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com