Aurelia 为什么我';我没有在激活方法中获取参数?
我有三节课要上。首先,家长:Aurelia 为什么我';我没有在激活方法中获取参数?,aurelia,Aurelia,我有三节课要上。首先,家长: import { Router, RouterConfiguration } from 'aurelia-router'; export class MainPage { router: Router; configureRouter(config: RouterConfiguration, router: Router) { config.map([ { route: '', redirect:
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" });
但是当我到达调试器
断点时,没有参数
,它是未定义的
。根据文档,应该有一个传递给activate
方法的对象,包含路由的参数。哪里出错了?使用激活方法。
params参数被传递到activate
,而不是像上面写的那样附加在上
async activate(params, routeConfig)
{
debugger;
this.events = <any> await this.services.getEvents(params.name);
}
异步激活(参数,routeConfig)
{
调试器;
this.events=等待this.services.getEvents(params.name);
}
虽然你在问题中提到了激活
,但我想这不是一个真正的问题,只是一个打字错误。昨晚我似乎太累了!我在试图弄明白为什么我的activate
(是的,真的,activate
)不起作用时遇到了这个问题:)。事实证明,如果我删除async
,它确实可以工作,但是这里的示例使用async
参数是否支持async
?