File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed
packages/schematics/angular/module
files/__name@dasherize@if-flat__ Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 11import { NgModule } from '@angular/core';<% if (commonModule) { %>
22import { CommonModule } from '@angular/common';<% } %><% if (lazyRouteWithoutRouteModule) { %>
33import { Routes, RouterModule } from '@angular/router';<% } %>
4- <% if (routing || lazyRouteWithRouteModule) { %>
4+ <% if ((!lazyRoute && routing) || lazyRouteWithRouteModule) { %>
55import { <%= classify(name) %>RoutingModule } from './<%= dasherize(name) %>-routing.module';<% } %>
66<% if (lazyRouteWithoutRouteModule) { %>
77const routes: Routes = [
@@ -11,7 +11,7 @@ const routes: Routes = [
1111@NgModule({
1212 declarations: [],
1313 imports: [<% if (commonModule) { %>
14- CommonModule<% } %><% if (routing || lazyRouteWithRouteModule) { %>,
14+ CommonModule<% } %><% if ((!lazyRoute && routing) || lazyRouteWithRouteModule) { %>,
1515 <%= classify(name) %>RoutingModule<% } %><% if (lazyRouteWithoutRouteModule) { %>,
1616 RouterModule.forChild(routes)<% } %>
1717 ]
Original file line number Diff line number Diff line change @@ -288,5 +288,46 @@ describe('Module Schematic', () => {
288288 `loadChildren: () => import('../bar/bar.module').then(m => m.BarModule)` ,
289289 ) ;
290290 } ) ;
291+
292+ it ( 'should not add reference to RouterModule when referencing lazy routing module' , async ( ) => {
293+ // Delete routing module
294+ appTree . delete ( '/projects/bar/src/app/app-routing.module.ts' ) ;
295+
296+ // Update app.module to contain the route config.
297+ appTree . overwrite (
298+ 'projects/bar/src/app/app.module.ts' ,
299+ `
300+ import { NgModule } from '@angular/core';
301+ import { RouterModule } from '@angular/router';
302+ import { BrowserModule } from '@angular/platform-browser';
303+ import { AppComponent } from './app.component';
304+
305+
306+ @NgModule({
307+ imports: [BrowserModule, RouterModule.forRoot([])],
308+ declarations: [AppComponent],
309+ })
310+ export class AppModule {}
311+ ` ,
312+ ) ;
313+
314+ const tree = await schematicRunner
315+ . runSchematicAsync (
316+ 'module' ,
317+ {
318+ ...defaultOptions ,
319+ name : 'bar' ,
320+ route : 'bar' ,
321+ routing : true ,
322+ module : 'app.module.ts' ,
323+ } ,
324+ appTree ,
325+ )
326+ . toPromise ( ) ;
327+
328+ const content = tree . readContent ( '/projects/bar/src/app/bar/bar.module.ts' ) ;
329+ expect ( content ) . toContain ( 'RouterModule.forChild(routes)' ) ;
330+ expect ( content ) . not . toContain ( 'BarRoutingModule' ) ;
331+ } ) ;
291332 } ) ;
292333} ) ;
You can’t perform that action at this time.
0 commit comments