Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NgModule } from '@angular/core';<% if (commonModule) { %>
import { CommonModule } from '@angular/common';<% } %><% if (lazyRouteWithoutRouteModule) { %>
import { Routes, RouterModule } from '@angular/router';<% } %>
<% if (routing || lazyRouteWithRouteModule) { %>
<% if ((!lazyRoute && routing) || lazyRouteWithRouteModule) { %>
import { <%= classify(name) %>RoutingModule } from './<%= dasherize(name) %>-routing.module';<% } %>
<% if (lazyRouteWithoutRouteModule) { %>
const routes: Routes = [
Expand All @@ -11,7 +11,7 @@ const routes: Routes = [
@NgModule({
declarations: [],
imports: [<% if (commonModule) { %>
CommonModule<% } %><% if (routing || lazyRouteWithRouteModule) { %>,
CommonModule<% } %><% if ((!lazyRoute && routing) || lazyRouteWithRouteModule) { %>,
<%= classify(name) %>RoutingModule<% } %><% if (lazyRouteWithoutRouteModule) { %>,
RouterModule.forChild(routes)<% } %>
]
Expand Down
41 changes: 41 additions & 0 deletions packages/schematics/angular/module/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,46 @@ describe('Module Schematic', () => {
`loadChildren: () => import('../bar/bar.module').then(m => m.BarModule)`,
);
});

it('should not add reference to RouterModule when referencing lazy routing module', async () => {
// Delete routing module
appTree.delete('/projects/bar/src/app/app-routing.module.ts');

// Update app.module to contain the route config.
appTree.overwrite(
'projects/bar/src/app/app.module.ts',
`
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';


@NgModule({
imports: [BrowserModule, RouterModule.forRoot([])],
declarations: [AppComponent],
})
export class AppModule {}
`,
);

const tree = await schematicRunner
.runSchematicAsync(
'module',
{
...defaultOptions,
name: 'bar',
route: 'bar',
routing: true,
module: 'app.module.ts',
},
appTree,
)
.toPromise();

const content = tree.readContent('/projects/bar/src/app/bar/bar.module.ts');
expect(content).toContain('RouterModule.forChild(routes)');
expect(content).not.toContain('BarRoutingModule');
});
});
});