0

我想有一个特定的行为,但只有当我的路线是最后一条时。

例如,我有路线 1:“posts.index” 路线 2:“posts.index.show”

如果我直接调用它,我想在 post.index 中做一些事情,但如果我直接访问 posts.index.show 我不想调用它。有没有办法知道 post.index 是否是当前调用路由的最后状态。

4

1 回答 1

3

只有叶子路由是可达的,这意味着你可以遍历节点路由,但永远不要停留在它上面。

在您的情况下,posts.index永远不会是您路由器的最终状态。我建议你有类似的东西:

posts: Ember.Route.extend({
  route: 'posts',

  // connectOutlets as needed for layout purpose...

  collection: Ember.Route.extend({
    route: '/',

    // connectOutlets to render collection & so on...
  }),

  member: Ember.Route.extend({
    route: '/:id',

    // connectOutlets: here, you will at least store the instance for later use in children routes, and probably render its outlet

    show: Ember.Route.extend({
      route: '/',

      // connectOutlets if needed.
    })

    // here, add other routes like edit, ...
  })
})

member路由中,您可以进行通用处理(至少检索和渲染实例),然后在其connectOutlets函数内部根据叶子路由进行专门化。

于 2012-08-04T07:27:54.033 回答