You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lazy routing is so often used a technique, but we still don't have semantic enough error message when a module to lazy route is included in imports of AppModule. Removing this import makes lazy loading implemented correctly, but the error which is being thrown during the import is not correct at all. Similar topics:
Step 1. Generate a new component to lazy load, here it's ng g c about-us.
Step 2. Create its module, here it's about-us.module.ts.
Step 3. Add RouterModule.forChild in about-us.module.ts, sample code below:
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { AboutUsComponent } from './about-us/about-us.component';
@NgModule({
declarations: [AboutUsComponent],
imports: [RouterModule.forChild([{ path: '', component: AboutUsComponent }])]
})
export class AboutUsModule {}
Step 4. Add AboutUsModule (FeatureModule) to AppModule, AboutUsModule we want to lazy load, like that (code for app.module.ts):
AboutUsModule.
import { AppComponent } from './app.component';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { AboutUsModule } from '@app/about-us';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
BrowserAnimationsModule,
AboutUsModule
],
bootstrap: [AppComponent]
})
export class AppModule {}
Step 5. Create app-routing.module.ts to define paths, for about-us it would be like that:
Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.
If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.
🐞 Bug report
✍️ Description
Lazy routing is so often used a technique, but we still don't have semantic enough error message when a module to lazy route is included in imports of AppModule. Removing this import makes lazy loading implemented correctly, but the error which is being thrown during the import is not correct at all. Similar topics:
🔬 Minimal Reproduction
Step 1. Generate a new component to lazy load, here it's
ng g c about-us
.Step 2. Create its module, here it's
about-us.module.ts
.Step 3. Add RouterModule.forChild in about-us.module.ts, sample code below:
Step 4. Add AboutUsModule (FeatureModule) to AppModule, AboutUsModule we want to lazy load, like that (code for app.module.ts):
AboutUsModule.
Step 5. Create app-routing.module.ts to define paths, for about-us it would be like that:
Step 6. Add to app.component.html, below:
<router-outlet></router-outlet>
Step 7. Run ng serve, and navigate to localhost:4200/about-us, you should see an error like in Exception or Error section below.
🔥 Exception or Error
🌍 Your Environment
Describe the solution you'd like to have
Throw an error something like "AboutUsModule is incorrectly imported into AppModule, because it supposed to be lazy loaded."
The text was updated successfully, but these errors were encountered: