Vue Bridge(for Vue v3)
@module-federation/bridge-vue3 提供了用于 Vue V3 应用的 bridge 工具函数,其提供的 createBridgeComponent 可用于导出应用级别模块,createRemoteAppComponent 用于加载应用级别模块。Demo
安装
类型
示例
Remote
Host
路由模式
Bridge 支持三种路由模式,决定远程应用如何管理其内部导航:
Hash 路由示例
Memory 路由示例
方法
createRemoteAppComponent
optionsloader- type:
() => Promise<Module> - Purpose: Used to load remote modules, e.g.,
loadRemote('remote1/export-app')orimport('remote1/export-app')
- type:
export- type:
string - Purpose: Used to specify module export
- type:
asyncComponentOptions- type:
Omit<AsyncComponentOptions, 'loader'> - Purpose: Parameters that will be passed to defineAsyncComponent, except for the loader parameter
- type:
rootAttrs- type:
Record<string, unknown> - Purpose: Attributes that will be bound to the root container where the remote Vue application will be mounted
- type:
memoryRoute- type:
{ entryPath: string } - 用途:提供后,远程应用将使用 memory history(
createMemoryHistory)代替默认的 web history。entryPath设置远程应用挂载时导航到的初始路由。适用于远程应用在隔离上下文(例如弹窗或沙箱)中渲染且不应修改浏览器 URL 的场景。
- type:
hashRoute- type:
boolean - 用途:设为
true时,远程应用将使用基于 hash 的 history(createWebHashHistory)代替默认的 web history。路由路径会自动添加basename前缀。当宿主应用也使用 hash 路由时使用此选项。
- type:
- ReturnType
- type:
VueComponent - Purpose: Used to render remote module components
- type:
createBridgeComponent
bridgeInfo- type:
{ rootComponent: VueComponent; appOptions?: (params: AddOptionsFnParams) => ({ router?: Router }) } - 用途:用于传递根组件
appOptions接收以下参数:app:Vue 应用实例basename:从宿主路由获取的基础路径memoryRoute:memory 路由配置(如果宿主提供)hashRoute:是否启用 hash 路由(如果宿主提供)
- type:
- ReturnType
- type:
() => { render: (info: RenderFnParams) => void; destroy: (info: { dom: HTMLElement}) => void; }
- type: