我最近注意到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