Рассмотрим следующие два класса:Родитель по умолчанию маршрутизатор с маршрутизаторами дочерних
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
команду. Но тогда я потеряю корневой путь!
Как я могу создать родительский маршрутизатор с маршрутом по умолчанию и некоторые дочерние маршруты по маршруту по умолчанию?
Спасибо Эшли, вы всегда правы. – Mehran
Не говорите моей подруге, что вы сказали, что :-P –