0

我一直在修补 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-pageAngular,但不,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可以在这里找到

4

1 回答 1

4

您只需要从导入来自 AppMoule 的 @NgModule() )中删除DepartmentModule ,如下所示,

imports: [ BrowserModule, MdButtonModule, 
           RouterModule, routing]         //<---removed DepartmentModule declaration  

工作http ://plnkr.co/edit/qoZ3YCwSz0mQ5o974Dt0?p=preview

于 2016-09-11T08:00:50.527 回答