File tree 2 files changed +43
-2
lines changed
packages/schematics/angular/module
files/__name@dasherize@if-flat__
2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { NgModule } from '@angular/core';<% if (commonModule) { %>
2
2
import { CommonModule } from '@angular/common';<% } %><% if (lazyRouteWithoutRouteModule) { %>
3
3
import { Routes, RouterModule } from '@angular/router';<% } %>
4
- <% if (routing || lazyRouteWithRouteModule) { %>
4
+ <% if ((!lazyRoute && routing) || lazyRouteWithRouteModule) { %>
5
5
import { <%= classify(name) %>RoutingModule } from './<%= dasherize(name) %>-routing.module';<% } %>
6
6
<% if (lazyRouteWithoutRouteModule) { %>
7
7
const routes: Routes = [
@@ -11,7 +11,7 @@ const routes: Routes = [
11
11
@NgModule({
12
12
declarations: [],
13
13
imports: [<% if (commonModule) { %>
14
- CommonModule<% } %><% if (routing || lazyRouteWithRouteModule) { %>,
14
+ CommonModule<% } %><% if ((!lazyRoute && routing) || lazyRouteWithRouteModule) { %>,
15
15
<%= classify(name) %>RoutingModule<% } %><% if (lazyRouteWithoutRouteModule) { %>,
16
16
RouterModule.forChild(routes)<% } %>
17
17
]
Original file line number Diff line number Diff line change @@ -288,5 +288,46 @@ describe('Module Schematic', () => {
288
288
`loadChildren: () => import('../bar/bar.module').then(m => m.BarModule)` ,
289
289
) ;
290
290
} ) ;
291
+
292
+ it ( 'should not add reference to and 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
+ } ) ;
291
332
} ) ;
292
333
} ) ;
You can’t perform that action at this time.
0 commit comments