angular – 在多个命名路由器插座的情况下获取当前插座名称

前端之家收集整理的这篇文章主要介绍了angular – 在多个命名路由器插座的情况下获取当前插座名称前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我们的角度4应用中,我们有多个命名路由器插座.
所以网址就像:
    http://localhost:3000/main/(outletName1:Printers//outletName2:Printers)

假设一个组件显示在一个特定的命名路由器插座中.
组件已在构造函数中注入了Router,ActivatedRoute等.

组件如何从注入的对象(或其他可能的话)中检索路由器出口的名称

解决方法

我想你可以通过RoutesRecognized事件获得所有指定的出口.下面是一个示例代码.

this.router.events.filter((event) => event instanceof RoutesRecognized).subscribe((result) =>  {
  console.log(result);
  const routesRecognizedEvent =  <RoutesRecognized>result;
  const state = routesRecognizedEvent.state;

  if( state && state.root ) {
    const root = state.root;

    const children = root.children;

    const allOutlets =  children.map(c => c.outlet);

    // allOutlets contains outletnames of current activated route



  }
});

猜你在找的Angularjs相关文章