我期待在使用这样的时刻类似的东西(在iframe与子应用门户应用程序) 您可以在服务器和客户机之间的通信(在任一方向) window.postMessage发送数据。
因此,例如在服务器上的应用程序:
var iframe = document.getElementById('useriframe');
if (iframe == null) return;
var iWindow = (<HTMLIFrameElement>iframe).contentWindow;
iWindow.postMessage({"for":"user","data":"anything"}, 'http://localhost:4001');
,并在客户端应用程序(内嵌框架内举行)
export class AppComponent {
@HostListener('window:message',['$event'])
onMessage(e)
{
if (e.origin!="http://localhost:4200")
{
return false;
}
if (e.data.for=="user")
{
alert('here i am');
}
}
显示子帧路线父 所以,我的实现将令牌和用户信息从shell应用程序传递给子iFrame,并将路由信息从子应用程序传递回shell,以便url反映在第儿童申请。 在孩子应用程序,你可能会有这样的路线:
[userapp]/edituser /用户名
,我们希望将其发布到父应用程序,并显示类似的路线:
http://mywebsite/main/application/user#edituser/bob
注意,我们使用#标签来标记一个孩子的路线,和在你的孩子,你的应用程序每一个拦截导航事件,并通过
export class MyRoutingComponent implements OnInit {
constructor(private router: Router) {
router.events.subscribe((event: Event)=>{
if (event instanceof NavigationEnd){
let url=(<NavigationEnd>event).url;
if (url.length>1)//don't post message about base route '/'
window.parent.postMessage({"for":"dashboard", "operation":"changeroute","route":url},'*')
}
})
}
发布新的路线,然后在父应用解析消息,并用它来更新显示的位置路径。
url = url +'#' + route;
this.location.go(url);