为什么我没有在激活方法中获取参数?

时间:2016-10-24 02:33:40

标签: aurelia aurelia-router

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方法的对象,其中包含路由的参数。哪里出错?

1 个答案:

答案 0 :(得分:3)

使用activate方法。

如上所述,params参数传递给attached,而不是async activate(params, routeConfig) { debugger; this.events = <any> await this.services.getEvents(params.name); }

{{1}}