Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 我需要一种方法,仅当用户路由到该链接时,才能将子路径作为LazyLoad从dashboard(父组件)加载为LazyLoad_Angular_Lazy Loading - Fatal编程技术网

Angular 我需要一种方法,仅当用户路由到该链接时,才能将子路径作为LazyLoad从dashboard(父组件)加载为LazyLoad

Angular 我需要一种方法,仅当用户路由到该链接时,才能将子路径作为LazyLoad从dashboard(父组件)加载为LazyLoad,angular,lazy-loading,Angular,Lazy Loading,我正在开发一个角度应用程序,我需要大部分组件都是惰性负载, 我有一个仪表板组件,它本身就是延迟加载,例如,在该仪表板中,我需要其他延迟加载组件 组成部分1 构成部分2 下面的代码来自文件app-routing.mmodule.ts const routes: Routes = [ { path: 'dashboard', loadChildren: () => import('./dashboard/dashboard.module').then(m => m.Da

我正在开发一个角度应用程序,我需要大部分组件都是惰性负载, 我有一个仪表板组件,它本身就是延迟加载,例如,在该仪表板中,我需要其他延迟加载组件

  • 组成部分1
  • 构成部分2
下面的代码来自文件app-routing.mmodule.ts

const routes: Routes = [
  { 
    path: 'dashboard', loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule),
    children: [
{
      path: 'component1', loadChildren:() => import('./dashboard/component1_folder/component1/component1.module').then(m => m.Component1Module)
    },
      path: 'component2', loadChildren:() => import('./dashboard/component2_folder/component2/component2.module').then(m => m.Component2Module)
    }
]
  }
];
当我运行代码时,出现以下错误:

main.ts:12 Error: Invalid configuration of route 'dashboard': children and loadChildren cannot be used together
    at validateNode (router.js:3398)
    at validateConfig (router.js:3367)
    at Router.resetConfig (router.js:4150)
    at new Router (router.js:3733)
    at Object.setupRouter [as useFactory] (router.js:5638)
    at Object.factory (core.js:11378)
    at R3Injector.hydrate (core.js:11289)
    at R3Injector.get (core.js:11111)
    at injectInjectorOnly (core.js:899)
    at Module.ɵɵinject (core.js:903)
(anonymous) @   main.ts:12
invoke  @   zone-evergreen.js:364
run @   zone-evergreen.js:123
(anonymous) @   zone-evergreen.js:857
invokeTask  @   zone-evergreen.js:399
runTask @   zone-evergreen.js:167
drainMicroTaskQueue @   zone-evergreen.js:569
Promise.then (async)        
scheduleMicroTask   @   zone-evergreen.js:552
scheduleTask    @   zone-evergreen.js:388
scheduleTask    @   zone-evergreen.js:210
scheduleMicroTask   @   zone-evergreen.js:230
scheduleResolveOrReject @   zone-evergreen.js:847
then    @   zone-evergreen.js:979
bootstrapModule @   core.js:28074
zUnb    @   main.ts:11
__webpack_require__ @   bootstrap:84
0   @   main.js:11
__webpack_require__ @   bootstrap:84
checkDeferredModules    @   bootstrap:45
webpackJsonpCallback    @   bootstrap:32
(anonymous) @   main.js:1
有人能帮我做到这一点吗,因为Angular在一次加载所有组件时速度很慢。只有当用户路由到该链接时,我才需要一种从仪表板加载子路径的方法。

一个“路径”可以而不是同时具有以下两个属性:
子路径
加载子路径
。顺便说一句,所有组件都不能“延迟加载”(实际上是一个延迟加载的模块)。几乎初始模块必须为“正常”

您可以使用asapp router.ts之类的应用程序

const routes:routes=[
{
{路径:'Home',Component},
{path:'dashboard',loadChildren:()=>import('....')。然后(mod=>mod.dashboard)}
}
];
dashboard.ts

const lazyOneRoutes:Routes=[
{路径:'',组件:仪表板组件},
{path:'component1',loadChildren:()=>import('…')。然后(mod=>mod.component1Module)},
{path:'component2',loadChildren:()=>import('…')。然后(mod=>mod.component2Module)}
]

const routes:routes=[
{路径:'Home',HomeComponent},
{path:'dashboard',loadChildren:()=>import('....')。然后(mod=>mod.dashboard)},
{path:'dashboard/component1',loadChildren:()=>import('…')。然后(mod=>mod.component1Module)},
{path:'dashboard/component2',loadChildren:()=>import('…')。然后(mod=>mod.component2Module)}
];

感谢您对此进行澄清。