【问题标题】:How to namespace an ember route in Ember 1.11.0如何在 Ember 1.11.0 中命名 ember 路由
【发布时间】:2015-05-18 11:25:32
【问题描述】:

我的理解是 Ember 1.11.0 在路由器中弃用了resource,而只支持使用route。根据我所读到的,两者之间的区别在于 resource 创建了一个命名空间。见:What is the difference between a route and resource in New Router API?

所以问题是如何命名路由,以便在下面的示例中,我的 cmets 路由、控制器和视图不以“帖子”为前缀?

App.Router.map(function() {
  this.route("posts", { path: "/" }, function() {
    this.route("new", { path: "/new" });
    this.route("comments", { path: "/comments" }, function() {
      this.route("new", { path: "/new" });
    });
  });
});

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    尝试将resetNamespace: true 传递给类似的路线

    this.route("comments", { path: "/comments", resetNamespace: true }, function() {
      this.route("new", { path: "/new" });
    });
    

    【讨论】:

    • 虽然这是摆脱 this.resource 的最简单方法,但 resetNamespace 在技术上是一个私有 API,因此不能保证它会继续存在,这可能会或可能不会比坚持更好this.resource 已正式弃用。
    • @Ahmad resetNamespace 现在是一个公共 API。请参阅此ember documentation。还有这个issue
    • @Ahmad 哦……我没注意到。哈哈。
    【解决方案2】:

    您可以将resetNamespace 选项用于路由,如下所示:

    this.route('posts', {}, function() {
      this.route('comments', {resetNamespace: true});
    });
    

    【讨论】:

      【解决方案3】:

      目前,如果不使用 this.resource,则无法使用公共 API 来做到这一点,this.resource 已正式弃用并计划在 Ember 2.0 中删除。官方不支持使用 resetNamespace,因为它是一个私有 API,所以从技术上讲,它可能会在没有警告的情况下随时被删除。

      这个问题的官方解决方案是重构你的应用程序以接受评论路由和模板在帖子下。

      【讨论】:

      • 希望他们在未来为它公开某种公共 API,因为如果没有它,具有深度嵌套路由(甚至 3 级嵌套)的应用程序最终可能会得到很长的,有时甚至是奇怪的类名。
      • @cbonser 他们很可能会github.com/emberjs/ember.js/issues/11251
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-10
      • 1970-01-01
      • 1970-01-01
      • 2013-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多