簡體   English   中英

訪問功能模塊路由來自應用模塊的配置數據

[英]Access feature module routes config data from app module

有什么方法可以從應用程序的路由配置訪問功能模塊路由配置。 零件

我有一個延遲加載的功能模塊。 我想訪問我的app.module上的功能模塊路由數據,以根據 URL 的子路徑突出顯示我的側導航欄(KendoUI Drawer)菜單項。 例如,如果通過http://localhost:4200/parent/child-component-name到瀏覽器導航用戶應該看到在側導航欄中選擇的child-component-name

從'@angular/core'導入{ NgModule }; 從'@angular/router'導入{RouterModule};

------------ app.routing.module.ts --------------

const parentRoutes = [
  {
    path: '',
    redirectTo: 'parent',
    pathMatch: 'full',
  },
  {
    path: 'parent',
    loadChildren: () =>
      import('./modules/parent/parent.module').then(
        (m) => m.parent
      ),
  },
];

------------ child.routing.module.ts --------------

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中只提供了兩條路由。

You can reset the route config after modifying it for the feature module that you are lazy loading.

In order to access the route config of the feature module (in your case child routing module),you can try accessing _loadedRoutes and modify as per your need and reset overall routeconfig.

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM