为什么我扩展了RouterModule我得到了RouterOutlet声明的重复:
metadata_resolver.js:505Uncaught Error: Type RouterOutlet is part of the declarations of 2 modules: RouterModule and CustomRouterModule! Please consider moving RouterOutlet to a higher module that imports RouterModule and CustomRouterModule. You can also create a new NgModule that exports and includes RouterOutlet then import that NgModule in RouterModule and CustomRouterModule.
at CompileMetadataResolver._addTypeToModule (http://localhost:4200/main.bundle.js:22259:19)
at http://localhost:4200/main.bundle.js:22169:27
at Array.forEach (native)
at CompileMetadataResolver._loadNgModuleMetadata (http://localhost:4200/main.bundle.js:22160:54)
at CompileMetadataResolver._loadNgModuleSummary (http://localhost:4200/main.bundle.js:22073:31)
at http://localhost:4200/main.bundle.js:22147:51
at Array.forEach (native)
at CompileMetadataResolver._loadNgModuleMetadata (http://localhost:4200/main.bundle.js:22143:49)
at CompileMetadataResolver._loadNgModuleSummary (http://localhost:4200/main.bundle.js:22073:31)
以下是我如何扩展RouterModule。
import {RouterModule, Routes, ExtraOptions, Router} from "@angular/router";
export class CustomRouterModule extends RouterModule{
public static forRoot(routes: Routes, config?: ExtraOptions)
{
// Do something with routes here ...
return super.forRoot(routes, config);
}
public static forChild(routes: Routes, router?: Router)
{
// Do something with routes here ....
return super.forChild(routes);
}
}
我是否也获得了ngModule装饰器元数据'扩展' ?我想要实现的是在将路由添加到路由器时进行一些路由处理。在我将它们添加到路由器之前,我无法访问路由,因为我是懒惰加载模块。