qiankun微前端 angular基座

主应用(基座)

registerMicroApps

export declare function registerMicroApps<T extends ObjectType>(apps: Array<RegistrableApp<T>>, lifeCycles?: FrameworkLifeCycles<T>): void;

在这个方法中为微应用注册信息

参数一 apps

在其中注册微应用的信息,主应用会在浏览器url发生变化,便会自动触发 qiankun 的匹配逻辑,所有 activeRule 规则匹配上的微应用就会被插入到指定的 container 中,同时依次调用微应用暴露出的生命周期钩子

参数二 lifeCycles

其中暴露了五个生命周期钩子

export declare type FrameworkLifeCycles<T extends ObjectType> = {
    beforeLoad?: LifeCycleFn<T> | Array<LifeCycleFn<T>>;
    beforeMount?: LifeCycleFn<T> | Array<LifeCycleFn<T>>;
    afterMount?: LifeCycleFn<T> | Array<LifeCycleFn<T>>;
    beforeUnmount?: LifeCycleFn<T> | Array<LifeCycleFn<T>>;
    afterUnmount?: LifeCycleFn<T> | Array<LifeCycleFn<T>>;
};

可以在微应用的几个生命周期执行对应的操作 待确认

搭建流程

子应用

创建子项目

ng n xxx

ng add single-spa-angular

注意目前暂时还不支持angular11 当前新客服angular使用的版本都是9.1.12

安装依赖

npm i qiankun-ng-common -S`
npm i @angular-builders/custom-webpack@9.2.0 -D

要注意webpack的版本

angular 9 项目只能安装 9.x 版本,angular 10 项目可以安装最新版

再安装一下缺失的依赖

npm i

删除empty-route文件夹,添加公共的空组件

app1/app-routing.module.ts

const routes: Routes = [
  {
    path: '**',
    component: EmptyComponent
  }
]

待确认 不确定子应用需要增加空组件路由

更改子项目根组件选择器

app.component.ts

@Component({
  selector: 'app1-root', // 此处不能和基座项目的根组件选择器相同
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.less']
})
export class AppComponent {}

index.html

<body>
  <app1-root></app1-root>
</body>

启动项目

将基座项目启动端口改到7400,子项目启动端口改到7401后,运行下方命令分别启动基座项目和子项目。

- 启动基座项目

npm start

- 启动子项目

npm run serve:single-spa:app1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值