带有子路由器的默认父路由器 [英] A default parent router with child routers

查看:99
本文介绍了带有子路由器的默认父路由器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下两个类:

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/当我执行时:

The problem is that; in a page where the URL reads: http://localhost/ when I execute:

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

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

I get the error ERROR [app-router] Error: Route not found: events. But if I change the MainPage class to this:

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命令.但是那样我会失去根源!

In a page that URL reads http://localhost/entities, I can successfully execute the given navigateToRoute command. But then I'll lose the root route!

那么我如何拥有一个具有默认路由的父路由器以及该默认路由下的一些子路由?

So how can I have a parent router with a default route and some child routes under the default route?

推荐答案

如何使用重定向路由将默认路由重定向到entities?我在使用移动设备,不行,因此没有代码示例,但文档应对此进行解释.

How about using a redirect route to redirect the default route to entities? I'm on mobile right no, so no code sample, but the docs should explain it.

这篇关于带有子路由器的默认父路由器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆