Loading Applications
This chapter introduces how to use createRemoteAppComponent to load and integrate remote React applications in a host application.
What is createRemoteAppComponent?
createRemoteAppComponent is the core React Bridge API for loading remote React applications. It provides:
- Automatic Lazy Loading: Loads remotes only when needed
- Lifecycle Management: Handles mount/unmount automatically
- Router Integration: Integrates with React Router and supports basename injection
- Error Handling: Built-in loading/runtime error fallback support
- Styling: Supports
className/styleon the wrapper component
Installation
Basic Usage
Step 1: Configure Remote Modules
Add remote configuration to the host application's Module Federation config.
The following example uses Rsbuild configuration. Please adjust according to your build tool:
- Rsbuild:
@module-federation/rsbuild-plugin - Rspack:
@module-federation/enhanced/rspack - Webpack:
@module-federation/enhanced/webpack - Vite:
@module-federation/vite:::
Step 2: Create Remote Components
2.1 Define Loading and Error Components
2.2 Create Remote Application Component
2.3 Main Application Router Configuration
Remote Component Props
Router Props
basename: Set the base path for the remote applicationmemoryRoute: Memory router configuration
Style Props
style:React.CSSPropertiesclassName:string
Ref Support
ref:React.Ref<HTMLDivElement>(forwarded to the internal container)
Data Passing
- Pass props directly (e.g.
userId="123") or via thepropsobject.
createRemoteAppComponent API Reference
Function Signature
RemoteComponentParams<T, E>
RemoteComponentProps<T>
Parameter Details
loader
- Type:
() => Promise<T> - Required: Yes
- Description: Loads the remote module object
- Examples:
loading
- Type:
React.ReactNode - Required: Yes
- Description: UI shown while the remote is loading
- Examples:
fallback
- Type:
React.ComponentType<{ error: Error }> - Required: Yes
- Description: UI shown when loading/rendering fails; receives
error - Examples:
export
- Type:
E extends keyof T - Required: No
- Default:
'default' - Description: Selects which export to render from the loaded remote module
Example: if your remote module exports:
Host usage:
Bundle Size Optimization
React Router Dependency Explanation
By default, @module-federation/bridge-react includes react-router-dom in your bundle to provide:
- Automatic basename injection
- Router context passing
- Nested routing support
If you don't need React Router integration (or you use a different router), disable enableBridgeRouter to reduce bundle size (about ~3KB gzipped) and avoid unnecessary router integration.
How to Disable Router Dependency
:::tip Configuration Behavior
enableBridgeRouter: false: Automatically aliases to the router-free/baseentry.enableBridgeRouter: true/undefined: Includes router support (default). :::
:::info How It Works
When enableBridgeRouter: false, the plugin sets up an alias: