ice-lab / icestark

:tiger: Micro Frontends solution for large application(面向大型应用的微前端解决方案),站点国内镜像:https://icestark.gitee.io
https://micro-frontends.ice.work
MIT License
2.04k stars 174 forks source link

卸载主应用后怎么停止icestark环境? #712

Closed ywyanbin closed 10 months ago

ywyanbin commented 10 months ago

场景: 现在把飞冰的主应用挂载到了qiankun下,访问qiankun的其他子应用后再次访问飞冰的子应用,提示 icestark has been already started

export const initSubApp = (container) => {
  let appList = [];
  // eslint-disable-next-line no-undef
  const isDev = process.env.NODE_ENV === 'development';
  Object.keys(appsConfig).forEach((key) => {
  let app = {
    name: key,
    activePath: appsConfig[key].activePath,
    entry: isDev ? appsConfig[key].entryDev : appsConfig[key].entryPro,
    container: container,
    hashType: false,
    cached: true
  };
  appList.push(app);
  });
  registerMicroApps(appList);
  start({
  prefetch: true,
  onRouteChange: (url, pathname, query, path) => {
    store.set('currentPath', pathname);
  },
  shouldAssetsRemove: (url, element) => {
    // 先全部缓存住,可能会引起样式,以及一些js全局变量的冲突,后续优化
    return false;
  }
  });
};

export const removeSubApp = () => {
  let appList = [];
  Object.keys(appsConfig).forEach((key) => {
  appList.push(key);
  });
  console.log('<<<<移除子应用', appList);
  removeMicroApps(appList);
};

// 飞冰主应用下layout组件
useEffect(() => {
  console.log('ice环境', isInIcestark());
  const subAppBox = document.getElementById('sub-app-box');
  initSubApp(subAppBox);
  iceStore.on('currentPath', (path) => {
    if (path) {
      setHash(path);
    }
      setRefresh(false);
  });
  iceStore.on('menus', (menus) => {
    setInitMenus(menus);
  });
  return () => {
    removeSubApp();
  };
}, []);
ClarkXia commented 10 months ago

不建议这么用 飞冰的子应用可以兼容在 qiankun 下使用

ywyanbin commented 10 months ago

现在的业务场景各自的子应用跟主应用关系很密切,分不开,所以这么结合着开发,想看看有啥方法能处理目前这种情况

ClarkXia commented 10 months ago

start 不会多次执行,可以通过全局变量的方式做一些判断

ywyanbin commented 9 months ago

有抛出的方法停止start函数执行吗

DavidWuJay commented 8 months ago

兄弟你的主程序是icev3的嘛?

ywyanbin commented 8 months ago

2.7.1

gmqiyue commented 4 months ago

不建议这么用 飞冰的子应用可以兼容在 qiankun 下使用

我尝试在qiankun下接入ice2的子应用,提示找不到lifecycls,有怀疑过是我接入的配置问题,当我尝试使用ice3创建子应用接到qiankun里是正常的,同时还尝试过在ice3创建的主应用中分别尝试,都正常,所以是ice2子应用不兼容么?