在my previous example上工作更多,我有三节课。首先是父母:
import { Router, RouterConfiguration } from 'aurelia-router';
export class MainPage
{
router: Router;
configureRouter(config: RouterConfiguration, router: Router)
{
config.map([
{ route: '', redirect: 'entities' },
{ route: 'entities', name: 'entities', moduleId: './entities/entities', nav: true, title: 'Entities' },
{ route: 'structures', name: 'structures', moduleId: './structures/structures', nav: true, title: 'Data Structures' },
]);
this.router = router;
}
}
然后是更大的兄弟:
import { Router, RouterConfiguration } from 'aurelia-router';
export class Entities
{
private router: Router;
configureRouter(config: RouterConfiguration, router: Router)
{
config.map([
{ route: '', name: 'entities-list', moduleId: './list', nav: true, title: 'Entities' },
{ route: ':name/events', name: 'entity-events', moduleId: './events', nav: true, title: 'Events' },
]);
this.router = router;
}
}
最后是小妹妹:
import { inject, computedFrom } from 'aurelia-framework';
import { Services } from './services';
@inject(Services)
export class Event
{
private events = [];
constructor(private services : Services) {}
async attached(params, routeConfig)
{
debugger;
this.events = <any> await this.services.getEvents(params.name);
}
}
我使用以下方法调用导航到小妹妹:
this.router.navigateToRoute('entity-events', { name: "Some Name" });
但是当我到达debugger
断点时,没有params
,它是undefined
。根据文档,应该有一个传递给activate
方法的对象,其中包含路由的参数。哪里出错?
答案 0 :(得分:3)
activate
方法。如上所述,params参数传递给attached
,而不是async activate(params, routeConfig)
{
debugger;
this.events = <any> await this.services.getEvents(params.name);
}
。
{{1}}