1
考慮以下兩類:與子路由器默認的母路由器
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;
}
}
的問題是;在一個網頁,讀取網址: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 –