特定の動作をしたいのですが、ルートが最後の場合のみです。
たとえば、ルート1: "posts.index"ルート2:"posts.index.show"があります
post.indexに直接アクセスしている場合は、post.indexで何かを実行したいのですが、posts.index.showに直接アクセスしている場合は呼び出したくありません。post.indexが現在呼び出されているルートの最後の状態であるかどうかを知る方法はありますか?
特定の動作をしたいのですが、ルートが最後の場合のみです。
たとえば、ルート1: "posts.index"ルート2:"posts.index.show"があります
post.indexに直接アクセスしている場合は、post.indexで何かを実行したいのですが、posts.index.showに直接アクセスしている場合は呼び出したくありません。post.indexが現在呼び出されているルートの最後の状態であるかどうかを知る方法はありますか?
リーフルートのみが到達可能です。つまり、ノードルートをトラバースできますが、最終的にはそこに留まることはありません。
あなたの場合、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
関数内でリーフルートに従って特殊化することができます。