Skip to content

Commit 6819d6a

Browse files
eneajahopkozlowski-opensource
authored andcommitted
fix(migrations): flip the default standalone flag in route-lazy-loading migration (angular#58474)
Before v19, the default value of the standalone flag was false, this code change flips the logic in the migration to make it true by default. PR Close angular#58474
1 parent 7d0ba0c commit 6819d6a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

packages/core/schematics/ng-generate/route-lazy-loading/util.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export function isStandaloneComponent(node: ts.ClassDeclaration): boolean {
2323
const arg = decorator.expression.arguments[0];
2424
if (ts.isObjectLiteralExpression(arg)) {
2525
const property = findLiteralProperty(arg, 'standalone') as ts.PropertyAssignment;
26-
return property ? property.initializer.getText() === 'true' : false;
26+
if (property) {
27+
return property.initializer.getText() === 'true';
28+
} else {
29+
return true; // standalone is true by default in v19
30+
}
2731
}
2832
}
2933

packages/core/schematics/test/standalone_routes_spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,13 @@ describe('route lazy loading migration', () => {
335335
import {NgModule} from '@angular/core';
336336
import {provideRoutes} from '@angular/router';
337337
import {TestComponent} from './test';
338+
import {StandaloneByDefaultComponent} from './standalone-by-default';
338339
import {NotStandaloneComponent} from './not-standalone';
339340
340341
const routes = [
341342
{path: 'test', component: TestComponent},
342343
{path: 'test1', component: NotStandaloneComponent},
344+
{path: 'test2', component: StandaloneByDefaultComponent},
343345
];
344346
345347
@NgModule({
@@ -358,11 +360,20 @@ describe('route lazy loading migration', () => {
358360
`,
359361
);
360362

363+
writeFile(
364+
'standalone-by-default.ts',
365+
`
366+
import {Component} from '@angular/core';
367+
@Component({template: 'hello'})
368+
export class StandaloneByDefaultComponent {}
369+
`,
370+
);
371+
361372
writeFile(
362373
'not-standalone.ts',
363374
`
364375
import {Component, NgModule} from '@angular/core';
365-
@Component({template: 'hello'})
376+
@Component({template: 'hello', standalone: false})
366377
export class NotStandaloneComponent {}
367378
368379
@NgModule({declarations: [NotStandaloneComponent], exports: [NotStandaloneComponent]})
@@ -381,6 +392,7 @@ describe('route lazy loading migration', () => {
381392
const routes = [
382393
{path: 'test', loadComponent: () => import('./test').then(m => m.TestComponent)},
383394
{path: 'test1', component: NotStandaloneComponent},
395+
{path: 'test2', loadComponent: () => import('./standalone-by-default').then(m => m.StandaloneByDefaultComponent)},
384396
];
385397
386398
@NgModule({

0 commit comments

Comments
 (0)