首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Access功能模块从app模块路由配置数据。

Access功能模块从app模块路由配置数据。
EN

Stack Overflow用户
提问于 2022-08-05 18:38:46
回答 1查看 128关注 0票数 0

是否有任何方式访问功能模块路由配置从路由配置从应用程序。组件

我有一个功能模块,这是懒惰加载。我想访问功能模块路由数据在我的app.module,以突出显示我的侧导航栏(KendoUI抽屉)菜单项的基础上的KendoUI子路径。例如,如果通过http://localhost:4200/parent/child-component-name到浏览器导航,用户应该会看到在侧导航栏中选择的child-component-name

从‘@ NgModule /核心’导入{ RouterModule };从‘@router/路由器’导入{RouterModule};

代码语言:javascript
复制
const parentRoutes = [
  {
    path: '',
    redirectTo: 'parent',
    pathMatch: 'full',
  },
  {
    path: 'parent',
    loadChildren: () =>
      import('./modules/parent/parent.module').then(
        (m) => m.parent
      ),
  },
];

代码语言:javascript
复制
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中提供两条路由。

EN

回答 1

Stack Overflow用户

发布于 2022-09-20 10:18:51

您可以在对延迟加载的功能模块进行修改后重置路由配置。

为了访问功能模块的路由配置(在您的例子中是子路由模块),您可以尝试访问_loadedRoutes并根据您的需要进行修改,并重置整个路由图。

代码语言:javascript
复制
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>]._loadedRoutes
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73254061

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档