是否有任何方式访问功能模块路由配置从路由配置从应用程序。组件
我有一个功能模块,这是懒惰加载。我想访问功能模块路由数据在我的app.module,以突出显示我的侧导航栏(KendoUI抽屉)菜单项的基础上的KendoUI子路径。例如,如果通过http://localhost:4200/parent/child-component-name到浏览器导航,用户应该会看到在侧导航栏中选择的child-component-name。
从‘@ NgModule /核心’导入{ RouterModule };从‘@router/路由器’导入{RouterModule};
const parentRoutes = [
{
path: '',
redirectTo: 'parent',
pathMatch: 'full',
},
{
path: 'parent',
loadChildren: () =>
import('./modules/parent/parent.module').then(
(m) => m.parent
),
},
];const routes: Routes = [
{
path: '',
component:ParentViewComponent,
children:[
{
path:'',
component: FirstChildComponent,
},
{
path: 'second',
component: SecondChildComponent,
},
{
path: 'third',
component: ThirdChildComponent,
},
}
]在我的app.component.ts中,我能够使用this.router.config访问父路由数据,但只能在app.routing.module.ts中提供两条路由。
发布于 2022-09-20 10:18:51
您可以在对延迟加载的功能模块进行修改后重置路由配置。
为了访问功能模块的路由配置(在您的例子中是子路由模块),您可以尝试访问_loadedRoutes并根据您的需要进行修改,并重置整个路由图。
Const newConfig=this.router.config.map(routeConfig=>{
if(routeConfig.path==='parent')
{
// Here you can find the route configs for lazy loaded module for path 'parent'
console.log(outeConfig._loadedRoutes)
// Do the modifications here
}
return routeConfig
})
this.router.resetConfig(newConfig)
// ie; this.routee.config[<indexOfLazyloadedModule>]._loadedRouteshttps://stackoverflow.com/questions/73254061
复制相似问题