在Angular2中按路由名称获取路由组件

Mar*_*thy 2 angular

是否有一种简单的方法可以通过路由名称获取@RouteConfig中定义的路由组件?我尝试使用下划线代码,它可以工作,但我需要知道最简单的方法.

   let annotations = Reflect.getMetadata('annotations', MyApp)[0].configs; 
   let route = _.findWhere( annotations, {name: 'RouteName' } );
   let component = route.component;
Run Code Online (Sandbox Code Playgroud)

Gün*_*uer 5

您应该能够从中获取此信息 Instruction

router.generate(['/RouteName']).component.componentType;
Run Code Online (Sandbox Code Playgroud)