Skip to content
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

fix(@angular/cli): update schematics to use RouterModule when --routing flag is present #27851

Merged
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,12 +1,12 @@
import { TestBed } from '@angular/core/testing';<% if (routing) { %>
import { RouterTestingModule } from '@angular/router/testing';<% } %>
import { RouterModule } from '@angular/router';<% } %>
import { AppComponent } from './app.component';

describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({<% if (routing) { %>
imports: [
RouterTestingModule
RouterModule.forRoot([])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't RouterModule be sufficient in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just RouterOutlet ?

Copy link
Author

@theonly1me theonly1me Jun 14, 2024

Choose a reason for hiding this comment

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

Wouldn't RouterModule be sufficient in this case?

Yes just using RouterModule should be sufficient since we are not registering any routes, but I found this comment when looking at related issues, which is why I updated it to use RouterModule.forRoot with an empty list of routes. Please let me know if you think it is unnecessary and can be removed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@atscott, what do you suggest here?

Copy link
Contributor

Choose a reason for hiding this comment

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

RouterOutlet is the minimal thing to have in the imports here. If you aren’t trying to import anything more than is necessary, that’s the thing to do.

If you want developers to not have to learn about what parts they’re using and need to import, then RouterModule.forRoot([]) makes it work for cases where RouterLink is added to the component template (RouterModule alone would not).

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your response @atscott. @alan-agius4, @eneajaho From an ease-of-use standpoint I feel it may be better to use RouterModule.forRoot([]), but I can make the change to use RouterOutlet, if you prefer that instead.

],<% } %>
declarations: [
AppComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
RouterTestingModule
RouterModule.forRoot([])
],
declarations: [
AppComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
beforeEach(() => TestBed.configureTestingModule({
imports: [RouterTestingModule],
imports: [RouterModule.forRoot([])],
declarations: [AppComponent]
}));

Expand Down