Bridge
is a utility function provided by Module Federation
for loading application-level modules.
"Application-level modules" are modules that can run like applications, with framework rendering capabilities and routing abilities.
With Bridge
, you can render your application in different frameworks and ensure that routing between applications works collaboratively. This is particularly useful for micro-frontend applications.
Before reading this chapter, it's assumed you're familiar with:
@module-federation/bridge-react
is suitable for React framework types, currently supporting React v16, v17, and v18 versions.
This toolkit provides two APIs:
Used to create React application-type module exports. If your application is React-based and you want it to be loaded as an application-type module by another MF application, you should use this to create standard-compliant exports for your application.
Used to load application-type modules in a React application. The loaded module must be wrapped by
createBridgeComponent
.createRemoteComponent
will automatically create a rendering context in your application to ensure the module works properly.
For usage of @module-federation/bridge-react
, see Host demo and Remote demo.
@module-federation/bridge-vue3
is suitable for Vue framework types, currently supporting Vue v3 version.
This toolkit provides two APIs:
Used to create Vue application-type module exports. If your application is Vue v3-based and you want it to be loaded as an application-type module by another MF application, you should use this to create standard-compliant exports for your application.
Used to load application-type modules in a Vue application. The loaded module must be wrapped by
createBridgeComponent
.createRemoteComponent
will automatically create a rendering context in your application to ensure the module works properly.
Bridge is mainly used to solve two problems:
These two issues are important features in "micro-frontend frameworks"
Currently, Module Federation
provides official bridge toolkits. If you need bridge toolkits for other frameworks, you can provide feedback through issues, or refer to the existing Bridge
implementation.
The implementation of Bridge
is very simple, with the core based on DOM
rendering. Here's some pseudocode:
Exporting module
Loading module