我最近注意到Ember Router的一些東西,它只允許導航到葉子路線 - 沒有子路線的路線。爲什麼Ember路由器只允許導航到葉子路由?
現在,除非我不正確地做事,否則這看起來像是設計中的錯誤/錯誤。
讓我們舉個例子是這樣的:
我有項目的集合,每個項目都有很多的合作者,有了這個,我想建立一個UI有一個3欄佈局(像您的標準的桌面電子郵件客戶端)在左邊我有一個項目列表,當點擊一個項目時,中間一列顯示了一個協作者列表,點擊一個協作者將其詳細信息加載到右側列中。
現在,在點擊一個項目時,我想導航到/projects/1
,點擊一個協作者時導航到/projects/1/collaborators/23
。
這裏是說明嵌套路線的第一部分路由器:
App.reopen(
Router: Ember.Router.extend(
enableLogging: true
location: 'hash'
root: Ember.Route.extend(
index: Ember.Route.extend(
route: '/'
redirectsTo: 'projects'
)
projects: Ember.Route.extend(
# This route is not routable because it is not a leaf route.
route: '/projects'
connectOutlets: (router) ->
# List projects in left column
router.get('applicationController').connectOutlet('projects', App.projects)
show: Ember.Route.extend(
# This route is routable because it is a leaf route.
route: '/:project_id'
connectOutlets: (router, project) ->
# Render the project into the second column, which actually renders
# a list of collaborators.
router.get('projectsController').connectOutlet('project', project)
)
)
)
)
)
正如你會看到餘燼不會調用updateRoute(設置URL),直至過渡到root.projects.show
,因爲這條線的https://github.com/emberjs/ember.js/blob/master/packages/ember-routing/lib/routable.js#L81
有沒有其他人做過這樣的事情?有沒有更好的方法來設計這個?
謝謝布拉德利,這似乎是伎倆。 – Ivan 2012-07-08 07:55:57
非常聰明。謝謝你的提示。 – nembleton 2012-07-08 10:33:24
@BradleyPriest我對此有一個[問題](http://stackoverflow.com/questions/11377498/ember-js-crud-scenarios-specifying-view-from-within-a-route)。我發現很難理解如何在CRUD場景中使用Ember.Router。你可以看一下嗎? – MilkyWayJoe 2012-07-08 11:22:58