1

我正在阅读有关路由的 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,以及这个插件:https ://plnkr.co/edit/ 6Mdn7qUblMtktpQyFJAc似乎表明我必须像上面那样设置我的路由器。这是有原因的还是我错过了什么?

4

0 回答 0