我正在处理关于路由的Angular2文档,并且已经建立了一个包含3个兄弟姐妹的测试应用程序,其中一个兄弟姐妹有三个孩子。我已经设置了路由器,但我只能通过设置“redirectTo”属性来重定向到其中一个子节点来路由到子节点的父节点。如果我省略该属性,我会收到以下错误:“错误:未捕获(在承诺中):错误:无法匹配任何路由:'test_landing'。但是,我有内容,我想在路由到父级时显示,我失去了它通过重定向。
Here is my router:
import { provideRouter, RouterConfig } from '@angular/router';
import { DashboardComponent } from './dashboard.component';
import {MaterialTest} from './materialtest.component';
//parent sibling with children
import { TestLanding } from './testlanding.component';
import { TestPage1 } from './test1.component';
import { TestPage2 } from './test2.component';
import { TestPage3 } from './test3.component';
const routes: RouterConfig = [
{ path: '', redirectTo: '/dashboard', pathMatch: 'full'},
{ path: 'dashboard', component: DashboardComponent},
{ path: 'material_test', component: MaterialTest},
{ path: 'test_landing', component: TestLanding ,
children: [
{ path: '', redirectTo:'test1', pathMatch: "full"}, //Error: Uncaught (in promise): Error: Cannot match any routes: 'test_landing'
{ path: 'test1', component: TestPage1 },
{ path: 'test2', component: TestPage2 },
{ path: 'test3', component: TestPage3 }
]
}
]
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];
我还阅读了这里的优秀文档:http://angular-2-training-book.rangle.io/handout/routing/routeparams.html,以及这个plunker:https://plnkr.co/edit/6Mdn7qUblMtktpQyFJAc而且似乎建议我必须像上面那样设置我的路由器。这是有原因还是我错过了什么?