小编McA*_*ome的帖子

延迟加载模块的 Angular onSameUrlNavigation

我有延迟加载模块数据重新获取的问题。onSameUrlNavigation 根本不起作用

我有一个单独的路由模块用于延迟加载功能,也许我无法正确集成 onSameUrlNavigation

项目结构:

app/
    app.component.ts
    app.module.ts
    app-routing.module.ts
        someFeature/
            someFeature.module.ts
            someFeature-routes.module.ts
            someFeature.component.ts
Run Code Online (Sandbox Code Playgroud)

应用路由模块代码:

app/
    app.component.ts
    app.module.ts
    app-routing.module.ts
        someFeature/
            someFeature.module.ts
            someFeature-routes.module.ts
            someFeature.component.ts
Run Code Online (Sandbox Code Playgroud)

懒加载路由模块:

    const routes: Routes = [
      {
        path: '',
        component: someFeatureComponent,
      },
    ];
    @NgModule({
      imports: [RouterModule.forChild(routes)],
      exports: [RouterModule],
    })
Run Code Online (Sandbox Code Playgroud)

组件代码:

    ngOnInit(): void {
    this.unsubscribe$ = new Subject<void>();
    this.route
      .queryParams.pipe(
      takeUntil(this.unsubscribe$),
      map(p => {
        this.loading = true;
        if (p.page && p.limit) {
          this.page = p.page;
          this.limit = p.limit;
        }
        return {
          page: this.page,
          limit: this.limit,
        };
      }),
      flatMap((f) => …
Run Code Online (Sandbox Code Playgroud)

javascript lazy-loading rxjs angular-routing angular

6
推荐指数
1
解决办法
1965
查看次数