-
Notifications
You must be signed in to change notification settings - Fork 12k
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
fix(@angular/cli): update schematics to use RouterModule when --routing flag is present #27851
Conversation
import { AppComponent } from './app.component'; | ||
|
||
describe('AppComponent', () => { | ||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({<% if (routing) { %> | ||
imports: [ | ||
RouterTestingModule | ||
RouterModule.forRoot([]) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just RouterOutlet
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution. Could you please update the commit message scope to @schematics/angular
?
…--routing flag is present update schematics to use RouterModule instead of RouterTestingModule when generating a new project with the --routing flag Fixes angular#27691
aa7be7f
to
27619a2
Compare
@alan-agius4 My bad, I've updated it now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The changes were merged into the following branches: main, 18.0.x |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
update schematics to use RouterModule instead of RouterTestingModule when generating a new project with the --routing flag
Fixes #27691
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Running
ng new --inline-style false --inline-template false --package-manager bun --routing --skip-git --standalone false --strict true --ssr false --style scss my-test-app
generates a new project with theRouterTestingModule
which is deprecatedIssue Number: #27691
What is the new behavior?
Running
ng new --inline-style false --inline-template false --package-manager bun --routing --skip-git --standalone false --strict true --ssr false --style scss my-test-app
generates a new projects with theRouterModule
Does this PR introduce a breaking change?
Other information
NA