- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我的应用程序绑定(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/
我有以下设置: 我有一个标题 Controller ,它控制页面的顶部导航栏。输入不同的路线时,我想更改导航布局。我遇到的问题是我只能在用户刷新页面时检测到路由。 例子: ... Product N
每次我将值传递给抽屉配置时,我都会收到此错误,但是当我在不传递任何配置的情况下使用它时,它工作正常。 我使用这个时出错: const Drawer = DrawerNavigator({ About
我正在尝试为我的抽屉布局使用自定义组件。下面是我的自定义抽屉组件: CustomDrawer.js: class CustomDrawer extends Component { navigate
我想导航到同一屏幕但具有不同的参数。所以想象一下 导航至MyRouteName 在此屏幕上单击一个按钮,该按钮应将我导航至 MyRouteName,但具有不同的参数。 目前我已经尝试过 this.pr
当将 expo 从 (16.0.0) 更新到 (24.0.0) 并将导航从 (git+ https://github.com/react-community/react-navigation.git
我正在使用 Angular 2 开发一个项目,但我遇到了一个问题。我已经创建了一个链接组件,我可以像这样使用它: Add channel 该组件检查当前路由是否与通过参数传递的路由相同,如果是,则应用
我只是对为什么我的 RedirectToRoute() 方法不起作用感到困惑。我有一个这样的 RouteConfig.cs 文件 routes.MapRoute( "pattern1",
有点令人困惑的一件事是路由名称和键之间的区别以及为什么要使用一个和另一个。并且,如何处理重复的路由名称。 This documentation says您使用的 routeName导航到屏幕,然后是
我有一个嵌套路线,我想在该路线上做一些事情。为此,我需要确定我何时处于该路线上。 我想从家长路线或 Controller 执行此操作。我尝试过使用 routeName fullRouteName 在父
我使用 ember-models-table 在我的应用程序中显示表格。该表非常适合排序、分页等,但我尝试根据 id 从特定行路由到不同页面。它在示例中提到使用“routeName”但是当我使用它时会
我是一名优秀的程序员,十分优秀!