在我们的角度4应用中,我们有多个命名路由器插座.
所以网址就像:
http://localhost:3000/main/(outletName1:Printers//outletName2:Printers)
所以网址就像:
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 } });