【发布时间】:2017-03-16 11:03:30
【问题描述】:
这个问题是我原来的问题Linking directly to both parent+child views/controllers from the main navigation menu的后续问题
接受的答案很好,但后来当我动态添加第二个“childRoute”时,我注意到了一个问题。为了动态构建我的导航,我必须添加具有相同“路线”属性的多条路线。 (请参阅下面示例代码中的 app.js)。唯一的区别是“标题”和“设置”属性。
configureRouter(config, router){
config.title = 'Aurelia';
config.map([
{ route: 'shared-parent', moduleId: './shared-parent', settings: { childRoute: 'child-a' }, nav: true, title: 'Shared Parent - child-a' },
{ route: 'shared-parent', moduleId: './shared-parent', settings: { childRoute: 'child-b' }, nav: true, title: 'Shared Parent - child-b' },
...
]);
this.router = router;
}
我在视图中使用的设置属性:
<a if.bind="row.settings.childRoute" href.bind="row.href + '/' + row.settings.childRoute">${row.title}</a>
我知道它不漂亮,但它确实导航到正确的子路线。问题在于,它始终是 2 条路线中的最后一条,具有重复的“路线”属性被标记为活动。
我之所以添加 settings: {childRoute: 'child-a/b' } 而不是给它们像 route: 'shared-parent/child-a' 和 route: 'shared-parent/child-b' 这样的不同“路由”属性,是因为 URL 实际上会匹配 shared-parent/child-a/child-a 和 shared-parent/child-b/child-b,因为我们是第一次链接到共享父级。
这个实时可运行的gist应该清楚地显示问题(子路由永远不会激活):https://gist.run/?id=95469a9cb3a762d79da31e0b64248036
附言。 如果您对如何称呼此问题的标题有更好的了解,请随时对其进行编辑。
【问题讨论】:
标签: aurelia