
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
angular2-async-route-loader
Advanced tools
This is a webpack loader to Angular2 lazy module loading.
It's recommended to use this loader with webpack 2.x.
export const appRoutes: Routes = [
{path: "", component: MainHomeComponent},
{path: "about", component: MainAboutComponent },
{path: "sub", loadChildren: "./sub.module#SubModule" },
];
export const appRoutes: Routes = [
{path: "", component: MainHomeComponent},
{path: "about", component: MainAboutComponent },
{path: "sub", loadChildren: () => require("./sub.module")("SubModule") },
];
And this loader return a function to call the require
function with .ngfactory
suffix if the resource is generated by compiler-cli:
export const appRoutes: Routes = [
{path: "", component: MainHomeComponent},
{path: "about", component: MainAboutComponent },
{path: "sub", loadChildren: () => require("./sub.module.ngfactory")("SubModuleNgFactory") },
];
npm install angular2-load-children-loader -D
npm install @types/node -D
or
typings install node
export const appRoutes: Routes = [
{path: "", component: MainHomeComponent},
{path: "about", component: MainAboutComponent },
{path: "sub", loadChildren: "es6-promise!./sub.module#SubModule"}
];
The following repository uses this loader:
To load sub modules asynchronously with webpack, you use only es6-promise-loader. For example:
import { Routes, RouterModule } from "@angular/router";
import { MainHomeComponent } from "./main-home.component";
import { MainAboutComponent } from "./main-about.component";
export function loadSubModule(): any {
return require("es6-promise!../sub/sub.module")("SubModule");
}
export const appRoutes: Routes = [
{path: "", component: MainHomeComponent},
{path: "about", component: MainAboutComponent },
{path: "sub", loadChildren: loadSubModule},
];
OK, it works pretty well. But wait. It doesn't work in Angular2 AoT(offline compile) mode.
In AoT context the loadSubModule
function should return not SubModule
but SubModuleNgFactory
(generated by the ngc
command).
In other words, to keep routing configurations to work in the both JiT and AoT context, you should switch the sub module to load as this loader does.
MIT
FAQs
angular2 async route loader
We found that angular2-async-route-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.