You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular壳应用集成SSR/SSG应用的最优方案与通信方式咨询

Angular壳应用集成SSR/SSG子应用的方案探讨

现有架构(Web Component模式)

我有一个Angular壳应用,目前采用Web Component模式渲染子应用,使用ax-lazy-element。壳应用与Web Component子应用间的所有通信均通过Input和Output事件实现。

AS-IS架构图

Web Component子应用代码

import { Injector } from '@angular/core';
import { createCustomElement } from '@angular/elements';
import { AppComponent } from './app.component';

const element = createCustomElement(AppComponent, { injector });
customElements.define('my-microfrontend', element);

壳应用中动态加载Web Component

<my-microfrontend
  *axLazyElement="['https://cdn.example.com/microfrontend.js']"
  [inputProp]="data"
  (outputEvent)="handleEvent($event)">
</my-microfrontend>

Input/Output数据交互代码

import { Component, Input, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `<div>{{ inputProp }}</div>`,
})
export class AppComponent {
  @Input() inputProp: string;
  @Output() outputEvent = new EventEmitter<string>();

  someMethod() {
    this.outputEvent.emit('some data');
  }
}

需求与问题

我希望在该壳应用中加载并集成采用SSR(服务器端渲染)和SSG(静态站点生成)模式的Angular应用,但不确定此类场景下的最优集成方式及通信方案。

目标架构图

我曾考虑使用Iframe结合PostMessage实现,但该方案体验不佳,是否存在其他可行方案?

内容的提问来源于stack exchange,提问作者fixesMyCode

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 19:35:55