我有以下代码:
应用程序路由.module.ts
const routes: Routes = [
{
path: 'login',
component: LoginComponent
},
{
path: 'user',
loadChildren: './modules/user/user.module#UserModule',
canActivate: [AuthGuardService]
},
{
path: 'config',
loadChildren: './modules/config/config.module#ConfigModule',
canActivate: [AuthGuardService]
},
{
path: '',
redirectTo: '/user',
pathMatch: 'full'
},
{
path: '**',
redirectTo: '/user',
pathMatch: 'full'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes, {enableTracing: true})],
exports: [RouterModule]
})
export class AppRoutingModule {
}
和 App Router 插座一样
<router-outlet></router-outlet>
配置路由.module.ts
const configRoutes: Routes = [
{
path: 'lookups',
loadChildren: './lookup/lookup.module#LookupModule',
outlet: 'config',
canActivate: [AuthGuardService]
},
{
path: '',
component: ConfigComponent,
canActivate: [AuthGuardService],
},
{
path: '**',
redirectTo: '',
pathMatch: 'full'
}
];
@NgModule({
imports: [RouterModule.forChild(configRoutes)],
exports: [RouterModule]
})
export class ConfigRoutingModule {
}
并将路由器出口配置为
<router-outlet name="config></router-outlet>
查找路由.module.ts
const lookupRoutes: Routes = [
{
path: ':id/options',
component: LookupOptionComponent,
canActivate: [AuthGuardService]
},
{
path: '',
component: LookupComponent,
canActivate: [AuthGuardService],
},
{
path: '**',
redirectTo: '',
pathMatch: 'full'
}
];
@NgModule({
imports: [RouterModule.forChild(lookupRoutes)],
exports: [RouterModule]
})
export class LookupRoutingModule {
}
在里面ConfigComponent
,我在做this.router.navigate([
${path} ], {relativeTo: this.route});
where path
is lookups
。
问题是每当我路由到/config/lookups
或/config/lookups/1/options
重定向到/config
. 我NavigationEnd {id: 1, url: "/config/lookups", urlAfterRedirects: "/config"}
在控制台中看到,很明显它正在重定向到配置。我无法弄清楚它为什么会重定向并且无法转到查找组件。我在这里研究了其他问题,但没有用。任何帮助,将不胜感激。谢谢!