logologo
指南
实践
配置
插件
案例
博客
生态
Module Federation Examples
Practical Module Federation
Zephyr Cloud
Nx
简体中文
English
指南
实践
配置
插件
案例
博客
Module Federation Examples
Practical Module Federation
Zephyr Cloud
Nx
简体中文
English
logologo
概览

Bridge

Bridge 介绍

React Bridge

快速开始
导出应用
加载应用
加载模块
Vue Bridge

框架

框架概览

React

Basic CRA with Rsbuild
国际化 (i18n)

Modern.js

快速开始
动态加载生产者

Next.js

Basic Example
导入组件
路由和导入页面
使用 Express.js
预设

Angular

Angular CLI 设置
Micro-frontends with Angular
服务端渲染
使用 Service Workers
Authentication with Auth0
Authentication with Okta
拆分巨石应用
改造巨石应用
Edit this page on GitHub
Previous Page导入组件
Next Page使用 Express.js

#路由和导入页面

在 Next.js 中导入联合页面需要在 next 构建的工作方式的约束内操作。

#导入远程页面

Next 依赖于静态分析来确定如何构建或渲染页面。

由于模块联邦是在运行时的,因此 next 在构建时无法看到远程页面包含哪些导出。

这要求你在宿主内重新导出页面远程的页面 API / 数据生命周期。

#Sample Remote App

remote/pages/index.js
remote/pages/other.js
remote/pages/_app.js
import React from 'react';
import Head from 'next/head';

const Shop = (props) => {
  return (
    <div>
      <Head>
        <title>Shop</title>
      </Head>
      <pre>{JSON.stringify(props)}</pre>
    </div>
  );
};
Shop.getInitialProps = async () => {
  const fallback = {
    name: 'Luke Skywalker',
    height: '172',
    mass: '77',
    hair_color: 'blond'
  };
  return Promise.resolve(fallback);
};

export default Shop;

#Sample Host App

host/pages/index.js
host/pages/other.js
host/pages/_app.js
import Shop from 'remote/pages/index';
const Page = Shop;
Page.getInitialProps = Shop.getInitialProps;
export default Page;