【发布时间】:2016-09-11 07:42:55
【问题描述】:
我一直在修补 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 选择 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 可以在这里找到。
【问题讨论】:
-
您的预期行为是什么?
-
它是否首先加载
landing-page,它有一个按钮(重定向到45号部门)? -
如果我不提供路径,当然要到达
landing-page。
标签: angular angular2-routing angular2-router3