Skip to content

feat(material/schematics/navigation): enable routing option #19439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2020
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
Expand Up @@ -5,9 +5,9 @@
[opened]="(isHandset$ | async) === false">
<mat-toolbar>Menu</mat-toolbar>
<mat-nav-list>
<a mat-list-item href="#">Link 1</a>
<a mat-list-item href="#">Link 2</a>
<a mat-list-item href="#">Link 3</a>
<a mat-list-item <%= routing ? 'routerLink="/"' : 'href="#"' %>>Link 1</a>
<a mat-list-item <%= routing ? 'routerLink="/"' : 'href="#"' %>>Link 2</a>
<a mat-list-item <%= routing ? 'routerLink="/"' : 'href="#"' %>>Link 3</a>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
Expand Down
22 changes: 22 additions & 0 deletions src/material/schematics/ng-generate/navigation/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,26 @@ describe('material-navigation-schematic', () => {
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
});
});
describe('router option', () => {
it('should respect the option value if routing true', async () => {
const tree =
await runner
.runSchematicAsync(
'navigation', { routing: true, ...baseOptions }, await createTestApp(runner))
.toPromise();
const template = tree
.readContent('/projects/material/src/app/foo/foo.component.html');
expect(template).toContain('<a mat-list-item routerLink="/">Link 1</a>');
});
it('should respect the option value if routing false', async () => {
const tree =
await runner
.runSchematicAsync(
'navigation', { routing: false, ...baseOptions }, await createTestApp(runner))
.toPromise();
const template = tree
.readContent('/projects/material/src/app/foo/foo.component.html');
expect(template).toContain('<a mat-list-item href="#">Link 1</a>');
});
});
});
5 changes: 5 additions & 0 deletions src/material/schematics/ng-generate/navigation/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
"type": "boolean",
"default": false,
"description": "Specifies if the component is an entry component of declaring module."
},
"routing": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think that the schematic should be doing this check based on the app module and not provided as an option.

Copy link
Member

@devversion devversion May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this would be the nicest solution. Though that might be overly complicated as we'd need to check the imports of the module.

These checks generally are not reliable as in reality the Angular compiler supports partial evaluation (i.e. module can be specified in a separate file through an exported variable). Surely we could use the static interpreter as in FW update migrations, but that seems out of scope.

"type": "boolean",
"default": false,
"description": "Specifies whether Angular routing is enabled. This controls whether anchor elements use href or routerLink"
}
},
"required": ["name"]
Expand Down