angular - 在嵌套中使用 redirectTo
问题描述
我有这个非常简单的路由器配置:
export const routes: Routes = [
{
path: '',
component: MiddleComponent,
pathMatch: 'full',
children: [
{
path: '',
redirectTo: './task-queue',
pathMatch: 'full',
},
{
path: 'task-queue',
component: TestComponent,
},
]
},
];
演示:https ://stackblitz.com/edit/angular-a7sxdf?file=app%2Fapp.routing.ts
哪里MiddleComponent
的模板只是<router-outlet></router-outlet>
。
我希望在页面加载后我应该被重定向到,task-queue
但我不是。我可以看到MiddleComponent
渲染但TestComponent
不是。
解决方案
需要为测试队列添加另一个具有重定向属性的路径。
export const routes: Routes = [
{ path: '', redirectTo: '/task-queue' ,
pathMatch: 'full'},
{ path: '', component: MiddleComponent,
children: [
{ path: '', redirectTo: '/task-queue',pathMatch: 'full' },
{ path: 'task-queue', component: TestComponent }
]
}
];