Skip to content

Commit 31723b8

Browse files
feat(material/schematics): enable routing option (#19439)
1 parent a730898 commit 31723b8

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/material/schematics/ng-generate/navigation/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html.template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
[opened]="(isHandset$ | async) === false">
66
<mat-toolbar>Menu</mat-toolbar>
77
<mat-nav-list>
8-
<a mat-list-item href="#">Link 1</a>
9-
<a mat-list-item href="#">Link 2</a>
10-
<a mat-list-item href="#">Link 3</a>
8+
<a mat-list-item <%= routing ? 'routerLink="/"' : 'href="#"' %>>Link 1</a>
9+
<a mat-list-item <%= routing ? 'routerLink="/"' : 'href="#"' %>>Link 2</a>
10+
<a mat-list-item <%= routing ? 'routerLink="/"' : 'href="#"' %>>Link 3</a>
1111
</mat-nav-list>
1212
</mat-sidenav>
1313
<mat-sidenav-content>

src/material/schematics/ng-generate/navigation/index.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,26 @@ describe('material-navigation-schematic', () => {
155155
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
156156
});
157157
});
158+
describe('router option', () => {
159+
it('should respect the option value if routing true', async () => {
160+
const tree =
161+
await runner
162+
.runSchematicAsync(
163+
'navigation', { routing: true, ...baseOptions }, await createTestApp(runner))
164+
.toPromise();
165+
const template = tree
166+
.readContent('/projects/material/src/app/foo/foo.component.html');
167+
expect(template).toContain('<a mat-list-item routerLink="/">Link 1</a>');
168+
});
169+
it('should respect the option value if routing false', async () => {
170+
const tree =
171+
await runner
172+
.runSchematicAsync(
173+
'navigation', { routing: false, ...baseOptions }, await createTestApp(runner))
174+
.toPromise();
175+
const template = tree
176+
.readContent('/projects/material/src/app/foo/foo.component.html');
177+
expect(template).toContain('<a mat-list-item href="#">Link 1</a>');
178+
});
179+
});
158180
});

src/material/schematics/ng-generate/navigation/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@
9292
"type": "boolean",
9393
"default": false,
9494
"description": "Specifies if the component is an entry component of declaring module."
95+
},
96+
"routing": {
97+
"type": "boolean",
98+
"default": false,
99+
"description": "Specifies whether Angular routing is enabled. This controls whether anchor elements use href or routerLink"
95100
}
96101
},
97102
"required": ["name"]

0 commit comments

Comments
 (0)