Javascript 将路由href与子路由器一起使用

Javascript 将路由href与子路由器一起使用,javascript,aurelia,Javascript,Aurelia,我试图在子路由器的视图中使用route href属性。我的父路由器看起来是这样的: configureRouter(config, router){ config.title = 'Kali'; config.map([ // { route: '', moduleId: 'no-selection', title: 'Select'}, { route: ['', 'courses'], moduleId: 'courses' } ])

我试图在子路由器的视图中使用
route href
属性。我的父路由器看起来是这样的:

configureRouter(config, router){
    config.title = 'Kali';
    config.map([
        // { route: '', moduleId: 'no-selection', title: 'Select'},
        { route: ['', 'courses'],  moduleId: 'courses' }
    ]);

    this.router = router;
}
configureRouter(config, router){
    config.map([
        { route: ['', '/'], moduleId: 'no-selection', title: 'Select'},
        { route: '/:id',  moduleId: 'courses/course-detail' }
    ]);

    this.router = router;
}
我的孩子看起来是这样的:

configureRouter(config, router){
    config.title = 'Kali';
    config.map([
        // { route: '', moduleId: 'no-selection', title: 'Select'},
        { route: ['', 'courses'],  moduleId: 'courses' }
    ]);

    this.router = router;
}
configureRouter(config, router){
    config.map([
        { route: ['', '/'], moduleId: 'no-selection', title: 'Select'},
        { route: '/:id',  moduleId: 'courses/course-detail' }
    ]);

    this.router = router;
}
这是我的route href属性

<a route-href="route: '', params: { id: course.id }" click.delegate="$parent.select(course.id)">

有什么想法吗?谢谢。

看起来
route href
使用了路由的
name
属性

也许您的子路由器应该如下所示:

configureRouter(config, router){
    config.map([
        { route: ['', '/'], moduleId: 'no-selection', title: 'Select'},
        { route: '/:id',  moduleId: 'courses/course-detail', name: 'course-detail' }
    ]);

    this.router = router;
}
在你看来:

<a route-href="route: course-detail; params.bind: { id: course.id }" ...

您是否尝试使用完整路线而不是单独使用id?而且它看起来不像是在处理您的课程。id?是的,我尝试了
路线:课程,参数:{id:course.id}
,但也不起作用。在我引入儿童路由器之前,它确实起作用了。这根本不起作用
route href
this.route
传递给路由器的
generate
方法
generate
将其参数命名为“name”,但这与它无关。我试过了,但没用。不过,要是有就好了。不幸的是,我可能只需要为此准备一个测试用例。实际上,我收回了这个。我正在仔细研究这一点,看起来您可能是正确的-这仍然不起作用,但看起来路由识别器模块查看的是
route.handler.name
,路由配置作为处理程序传入。我真的不知道这是怎么回事,哎呀!我的机器刚刚开始工作。我们在
路线href
中使用了
,而我们本应该使用
脸掌。我已经编辑了答案,现在应该可以了。成功了。我想我不希望route href处理程序中有完整的JS表达式-我既不希望有分号,也不希望有
params.bind
语句。有这方面的文件吗?我愿意提供有关route href使用的文档,因为我相信它会帮助还不熟悉的人。我会说,在这样的表达式中看到绑定语言的一部分有点奇怪。我没有料到它会被解析。此外,我越想它…这与原始路由一起工作,没有任何子路由器参与。保持行为尽可能一致不是更好吗?
route href
处理程序可能应该访问它所在视图的底层JS文件,然后从那里遍历父链(如果需要)。这将增强模块化并促进统一的代码标准,而不管嵌套级别如何。