具有子路由器的默认父路由器

时间:2016-10-23 23:12:44

标签: aurelia aurelia-router

考虑以下两个类:

import { Router, RouterConfiguration } from 'aurelia-router';

export class MainPage
{
    router: Router;

    configureRouter(config: RouterConfiguration, router: Router)
    {
        config.map([
            { 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: 'events', name: 'entity-events', moduleId: './events', nav: true, title: 'Events' },
        ]);

        this.router = router;
    }
}

问题在于;在我执行以下URL的页面中显示:http://localhost/

this.router.navigateToRoute('entity-events');

我收到错误ERROR [app-router] Error: Route not found: events。但是,如果我将MainPage类更改为:

import { Router, RouterConfiguration } from 'aurelia-router';

export class MainPage
{
    router: Router;

    configureRouter(config: RouterConfiguration, router: Router)
    {
        config.map([
            { 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;
    }
}

在URL读取http://localhost/entities的页面中,我可以成功执行给定的navigateToRoute命令。但是,我将失去根路线!

那么如何在默认路由下使用默认路由和一些子路由的父路由器?

1 个答案:

答案 0 :(得分:2)

如何使用重定向路由将默认路由重定向到entities?我在移动设备上没有,所以没有代码示例,但文档应该解释它。