0

我了解如何在使用时将自定义道具传递给不同的微应用,single-spa但我想知道如何获取 api 调用表单 app1 的输出并在 app2 中使用它。app1 正在使用react-redux,app2 将使用react hooks.

import {registerApplication, start} from 'single-spa'


registerApplication(
    'navBar',          // Name of this single-spa application
    () => import('./nav/navbar.app.js').then(module => module.navBar),
    () => true
)

registerApplication(
  'app1',          // Name of this single-spa application
  () => import('./root.app.js'),//loadingFunction, // Our loading function
  () => true, //activityFunction // Our activity function
)

registerApplication(
    'app2',          // Name of this single-spa application
    () => import('./app2/app2.app.js').then(module => module.app2),
    location =>
        location.pathname === '/app2' ||
        location.pathname.startsWith('/app2'),
    {
        some: 'value',
    }
)

start()

或者我如何调用 root api 调用并在所有微应用程序之间共享输出。以上是我的index.js,由webpack.

我正在使用 single-spa 版本 4.x 和 webpack 4.x

4

1 回答 1

2

在 single-spa 中共享应用程序状态是使用实用程序模块模式来创建一个“服务”来实现的,该“服务”可以使用跨微前端导入来跨所有微前端共享。

其中一个示例是使用 Rxjs 跨多个前端共享登录状态,您可以在此处找到:https ://github.com/filoxo/single-spa-example-rxjs-shared-state免责声明:我编写了这个示例。

于 2021-02-23T07:10:49.463 回答