角的延迟加载是2个模块的声明的一部分:AppModule和ProductModule!我说,每一个指南和仍然存在的问题,我必须由您的专业人士帮助如何思考。
我共享一个代码-
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{ path: 'product', loadChildren: () => import('./product/product.module').then(m => m.ProductModule) },
{ path: '**', redirectTo: 'product/home', pathMatch: 'full' }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';
import { HomeComponent } from 'src/app/home/home.component';
import { FavoriteComponent } from 'src/app/favorite/favorite.component';
import { AccountComponent } from 'src/app/account/account.component';
import { LoginComponent } from 'src/app/login/login.component';
import { RegisterComponent } from 'src/app/register/register.component';
import { InfoComponent } from 'src/app/info/info.component';
import { guards } from 'src/app/store/guards';
const routes: Routes = [
{ path: 'home', component: HomeComponent, canActivate: guards },
{ path: 'favorite', component: FavoriteComponent, canActivate: guards },
{ path: 'account', component: AccountComponent, canActivate: guards },
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'info', component: InfoComponent }
]
@NgModule({
declarations: [LoginComponent,RegisterComponent,InfoComponent],
imports: [
CommonModule,
RouterModule.forChild(routes),
]
})
export class ProductModule { }
整个问题
core.js:6014 ERROR Error: Uncaught (in promise): Error: Type LoginComponent is part of the declarations of 2 modules: AppModule and ProductModule! Please consider moving LoginComponent to a higher module that imports AppModule and ProductModule. You can also create a new NgModule that exports and includes LoginComponent then import that NgModule in AppModule and ProductModule.
Error: Type LoginComponent is part of the declarations of 2 modules: AppModule and ProductModule! Please consider moving LoginComponent to a higher module that imports AppModule and ProductModule. You can also create a new NgModule that exports and includes LoginComponent then import that NgModule in AppModule and ProductModule.
at syntaxError (compiler.js:2175)
at CompileMetadataResolver._addTypeToModule (compiler.js:20215)
at compiler.js:20115
at Array.forEach (<anonymous>)
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:20106)
at JitCompiler._loadModules (compiler.js:25824)
at JitCompiler._compileModuleAndComponents (compiler.js:25807)
at JitCompiler.compileModuleAsync (compiler.js:25769)
at CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:223)
at MergeMapSubscriber.project (router.js:6406)
at resolvePromise (zone-evergreen.js:797)
at resolvePromise (zone-evergreen.js:754)
at zone-evergreen.js:858
at ZoneDelegate.invokeTask (zone-evergreen.js:391)
at Object.onInvokeTask (core.js:39680)
at ZoneDelegate.invokeTask (zone-evergreen.js:390)
at Zone.runTask (zone-evergreen.js:168)
at drainMicroTaskQueue (zone-evergreen.js:559)
如果需要更多信息,我很高兴添加,但是我必须得到您的帮助,非常感谢!!
当前,您正在同时使用AppModule和ProductModule的Login组件。仅将其放在其中一个模块中。如果要在两个模块中都访问它。创建第三个模块,并将logincomponent放入该第三个模块的声明和导出数组中。然后将第三个模块导入appmodule和productmodule中。