3

我需要从 Ember 获取当前 url 作为“redirectTo”参数。该参数将用于在用户从其他应用程序登录后将用户重定向回同一页面。网址看起来像

http://test.com/apps/#/tables/7

我发现这篇文章可以从应用程序中获取 currentPath/route。它提供了当前的路由名称,但我想知道如何从 Ember 获取包含 id 的完整路径。我有一个嵌套路由声明,如下所示。

App.Router.map(function() {
  this.resource('tables', function() {
    this.resource('table', { path: ':table_id' });
  });
});

欢迎任何建议。谢谢!

4

3 回答 3

3

观察currentPathApplicationController 中的并更新当前 URL:

App.ApplicationController = Ember.Controller.extend({
  currentPathDidChange: function() {
    App.currentUrl = window.location.href;
  }.observes('currentPath')
});
于 2013-06-17T21:19:45.013 回答
1

你可以只使用window.location吗?

var url = window.location.href;
于 2013-06-17T18:06:08.533 回答
-1

谢谢@Panagiotis Panagi,它有效。

此外,currentUrl 只能从应用程序控制器访问,因此如果您想从其他地方获取它,您可以将此代码添加到您要访问它的某个控制器:

export default Ember.Controller.extend({
  needs: ['application'],
  currentPath: Ember.computed.alias('controllers.application.currentPath'),
    ...

}
于 2015-06-27T15:41:44.873 回答