4

假设我有一个给定的 ember 应用程序

App = Ember.Application.create()

路由器

App.Router.map(function() {
  this.resource("posts", function() {
    this.resource("post", {
      path: "/:post_id"
    })
  });
});

每当应用程序输入给定的 /:post_id 时,我如何执行一个函数?

4

2 回答 2

7

您可以实施App.PostRoute以指定您的post路线的自定义行为。如果你不这样做,Ember 将在幕后创建这个类。

activate每次激活路由时都会在路由上调用钩子。

例子:

App.PostRoute = Ember.Route.extend({
  activate: function() {
    doSomething();
  }
});
于 2013-06-07T05:05:02.010 回答
0

在此处使用路由器请求生命周期中的钩子之一:http: //darthdeus.github.io/blog/2013/02/08/router-request-lifecycle/

于 2013-06-06T17:02:57.503 回答