Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@module-federation/bridge-react
Advanced tools
React bridge is used to load the routing module in mf, so that the routing module can work properly with the host environment.
React bridge is used to load the routing module in mf, so that the routing module can work properly with the host environment.
When to use
pnpm add @module-federation/bridge-react
Use createBridgeComponent create component provider
// ./src/index.tsx
import { createBridgeComponent } from '@module-federation/bridge-react';
function App() {
return ( <BrowserRouter basename="/">
<Routes>
<Route path="/" Component={()=> <div>Home page</div>}>
<Route path="/detail" Component={()=> <div>Detail page</div>}>
</Routes>
</BrowserRouter>)
}
export default createBridgeComponent({
rootComponent: App
});
set alias to proxy
//rsbuild.config.ts
export default defineConfig({
source: {
alias: {
'react-router-dom$': path.resolve(
__dirname,
'node_modules/@module-federation/bridge-react/dist/router.es.js',
),
},
},
server: {
port: 2001,
host: 'localhost',
},
dev: {
assetPrefix: 'http://localhost:2001',
},
tools: {
rspack: (config, { appendPlugins }) => {
delete config.optimization?.splitChunks;
config.output!.uniqueName = 'remote1';
appendPlugins([
new ModuleFederationPlugin({
name: 'remote1',
exposes: {
'./export-app': './src/index.tsx',
}
}),
]);
},
},
});
//rsbuild.config.ts
export default defineConfig({
tools: {
rspack: (config, { appendPlugins }) => {
config.output!.uniqueName = 'host';
appendPlugins([
new ModuleFederationPlugin({
name: 'host',
remotes: {
remote1: 'remote1@http://localhost:2001/mf-manifest.json',
},
}),
]);
},
},
});
Use the module
// ./src/index.tsx
import { createBridgeComponent } from '@module-federation/bridge-react';
const Remote1 = createBridgeComponent(()=> import('remote1/export-app'));
function App() {
return ( <BrowserRouter basename="/">
<ul>
<li>
<Link to="/">
Home
</Link>
</li>
<li>
<Link to="/remote1">
Remote1
</Link>
</li>
</ul>
<Routes>
<Route path="/" Component={()=> <div>Home page</div>}>
<Route path="/remote1" Component={()=> <Remote1 />}>
</Routes>
</BrowserRouter>)
}
const root = ReactDOM.createRoot(document.getElementById('root')!);
root.render(
<App />
);
FAQs
React bridge is used to load the routing module in mf, so that the routing module can work properly with the host environment.
The npm package @module-federation/bridge-react receives a total of 1,102 weekly downloads. As such, @module-federation/bridge-react popularity was classified as popular.
We found that @module-federation/bridge-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.