Angular懒加载-导入模块具有路由问题
创始人
2024-10-27 22:00:45
0

当我们将带有路由的导入模块添加到应用程序中时,如果我们尝试在懒加载时使用这些导入的模块,就会出现问题。因此,我们需要创建子路由组并将其添加到懒加载模块中。

例如,考虑以下示例:

在app-routing.module.ts中:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [
  { path: 'home', loadChildren: () => import('./home/home.module').then(m => m.HomeModule) },
  { path: 'dashboard', loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule) },
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

在dashboard-routing.module.ts中:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard.component';

const routes: Routes = [
  { 
    path: '', 
    component: DashboardComponent,
    children: [
      { path: 'overview', loadChildren: () => import('./overview/overview.module').then(m => m.OverviewModule) },
      { path: 'details', loadChildren: () => import('./details/details.module').then(m => m.DetailsModule) },
    ]
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class DashboardRoutingModule { }

在dashboard.module.ts中:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { DashboardRoutingModule } from './dashboard-routing.module';
import { DashboardComponent } from './dashboard.component';

@NgModule({
  declarations: [DashboardComponent],
  imports: [
    CommonModule,
    DashboardRoutingModule
  ]
})
export class DashboardModule { }

在overview-routing.module.ts中:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { OverviewComponent } from './overview.component';

const routes: Routes = [
  { 
    path: '', 
    component:

相关内容

热门资讯

黑科技了解(德州之星app有漏... 黑科技了解(德州之星app有漏洞吗)外挂透明挂辅助挂(透视)好像有挂(黑科技方法)1、玩家可以在德州...
微扑克辅助算牌器!微扑克如何让... 微扑克辅助算牌器!微扑克如何让系统发好牌,(微扑克)总是真的是有挂,曝光教程(黑科技功能)小薇(透视...
辅助黑科技(wepoke辅助真... 辅助黑科技(wepoke辅助真的假的)外挂黑科技辅助安装(透视)一直是真的有挂(黑科技解密)1、操作...
wepokeai代打!wepo... wepokeai代打!wepoke是不是有辅助,(WEPOKE)真是是有挂,高科技教程(黑科技透明)...
微扑克辅助插件挂!wpk透视外... 微扑克辅助插件挂!wpk透视外挂,(WpK)一贯是有挂,wepoke教程(黑科技脚本);1、首先打开...
黑科技代打(德州ai辅助有用)... 黑科技代打(德州ai辅助有用)外挂透视辅助安装(透视)确实真的有挂(黑科技插件);1、构建自己的德州...
德州wepower辅助器ai!... 德州wepower辅助器ai!德州之星辅助软件,(德州ai)真是真的是有挂,解密教程(黑科技透明挂)...
黑科技玄学(wepoke一定有... 黑科技玄学(wepoke一定有挂)外挂透明挂辅助助手(透视)一贯真的是有挂(黑科技解密)1、进入游戏...
wepoke有没有挂!wepo... wepoke有没有挂!wepok软件透明挂,(wEpoke)其实是真的有挂,透明挂教程(黑科技功能)...
黑科技苹果版(智星德州菠萝偷偷... 黑科技苹果版(智星德州菠萝偷偷看牌功能)外挂透明挂辅助技巧(透视)总是存在有挂(黑科技规律);所有人...