我一直在修补 RC6 一段时间,希望最终路由到嵌套的子组件能够开箱即用。好吧,没有这样的运气。我现在看到的效果是redirectTo
默认路由只是被忽略了,相反,Angular 直接进入第一个子组件。
import { Route, RouterModule } from '@angular/router';
import { LandingPageComponent } from 'src/landing-page.component';
import { DepartmentModule } from 'src/department/department.module';
const routes: Route[] = [
{ path: '', redirectTo: 'landing-page', pathMatch: 'full' },
{ path: 'landing-page', component: LandingPageComponent },
{ path: 'department', loadChildren: () => DepartmentModule }
];
export const appRoutingProviders: any[] = [];
export const routing = RouterModule.forRoot(routes, {enableTracing:true});
您应该认为输入任何 URL 都会将我带到landing-page
Angular,但不,Angular 选择department
的原因超出了我的范围。
从那时起,一切都按预期工作,然后我可以导航到子路线
import { Route, RouterModule } from '@angular/router';
import { DepartmentComponent } from './department.component';
import { DepartmentDetailsComponent } from './department-details.component';
const departmentRoutes: Route[] = [
{ path: '', component: DepartmentComponent },
{ path: ':id', component: DepartmentDetailsComponent }
];
export const departmentRouting = RouterModule.forChild(departmentRoutes);
不过这里奇怪的是,我需要
<a [routerLink]="['../..']">
导航 1 级备份。可能,这两个问题是相关的。
有谁知道我错过了什么?plnkr可以在这里找到。