我的Angular2应用程序中有一个多级路由,并且我试图尽可能干净地管理路由,但是子重定向不断对其父级进行预处理,而我无法找到解决方法。
在我的app.routes.ts中,我有......
const appRoutes: Routes = [
{ path: '', redirectTo: 'matters', pathMatch: 'full' }
, { path: 'login', component: LoginComponent }
, { path: '**', component: NoContentComponent }
];
My Parent Route is as follows...
export const routes: Routes = [
{
path: 'matters', component: MatterListComponent, canActivate: [LoginAuthGuard]
, children:
[ { path: '', component: MatterNotSelectedComponent, pathMatch: 'full' }
, { path: ':id', loadChildren: () => ChildModule }
]
}
];
在我的儿童路线中,我有......
export const routes: Routes = [
{ path: '', component: MyComponent, canActivate: [LoginAuthGuard],
children:
[
{ path: '', redirectTo: 'summary', pathMatch: 'full' },
{ path: 'summary', component: MyComponent },
路由工作正常,但它始终重定向到summary
,并且在提供空路径时无关紧要。我在pathMatch上尝试了“前缀”,但似乎没有改变这一点。我错过了什么吗?
答案 0 :(得分:0)
似乎是一个简单的修复,添加了
{ path: '', redirectTo: 'matters', pathMatch: 'full' },
到父路线: - )