考虑以下两个类:
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
命令。但是,我将失去根路线!
那么如何在默认路由下使用默认路由和一些子路由的父路由器?
答案 0 :(得分:2)
如何使用重定向路由将默认路由重定向到entities
?我在移动设备上没有,所以没有代码示例,但文档应该解释它。