我想知道如何使用动态元素在 Ember 中获取当前路径?
我知道有
@get('currentPath')
在 applicationController 中,但这只会给我“user.show”,我也希望能够检索像“/users/1”这样的路径。
我知道我可以通过 window.location.href 做到这一点,但还有其他(“ Ember ”)方法吗?
问候
彼得
最佳答案
我不确定这是否符合 Ember Way,因为它没有在文档中列出,但 Controller 的目标对象包含对 document.location
的引用。还有一个名为 lastSetURL
的属性.
this.get('target').location.lastSetURL; // "/foo/1"
关于ember.js - 使用 ember.js 中的动态段获取当前路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16526813/