Skip to content

Commit 1a6a139

Browse files
committed
feat(@schematics/angular): enable routing by default for new applications
This commits updates the `routing` option in the `ng new` and `ng generation application` schematics to `true` by default and also removed the `Would you like to add Angular routing?` prompt. BREAKING CHANGE: Routing is enabled by default for new applications when using `ng generate application` and `ng new`. The `--no-routing` command line option can be used to disable this behaviour.
1 parent b3b4787 commit 1a6a139

File tree

10 files changed

+15
-48
lines changed

10 files changed

+15
-48
lines changed

packages/schematics/angular/application/index_spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ describe('Application Schematic', () => {
3131

3232
const defaultOptions: ApplicationOptions = {
3333
name: 'foo',
34-
routing: false,
3534
skipPackageJson: false,
3635
};
3736

@@ -566,8 +565,8 @@ describe('Application Schematic', () => {
566565
expect(component).toMatch(/standalone: true/);
567566
});
568567

569-
it('should create routing information when routing is true', async () => {
570-
const options = { ...defaultOptions, standalone: true, routing: true };
568+
it('should create routing information by default', async () => {
569+
const options = { ...defaultOptions, standalone: true };
571570

572571
const tree = await schematicRunner.runSchematic('application', options, workspaceTree);
573572

packages/schematics/angular/application/schema.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@
3939
},
4040
"routing": {
4141
"type": "boolean",
42-
"description": "Create a routing NgModule.",
43-
"default": false,
44-
"x-prompt": "Would you like to add Angular routing?",
42+
"description": "Creates an application with routing enabled.",
43+
"default": true,
4544
"x-user-analytics": "ep.ng_routing"
4645
},
4746
"prefix": {

packages/schematics/angular/ng-new/index_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('Ng New Schematic', () => {
5151
jasmine.arrayContaining([
5252
'/bar/tsconfig.app.json',
5353
'/bar/src/main.ts',
54+
'/bar/src/app/app.routes.ts',
5455
'/bar/src/app/app.config.ts',
5556
]),
5657
);

packages/schematics/angular/ng-new/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
},
9292
"routing": {
9393
"type": "boolean",
94-
"description": "Generate a routing module for the initial project.",
94+
"description": "Enable routing in the initial project.",
9595
"x-user-analytics": "ep.ng_routing"
9696
},
9797
"prefix": {

packages/schematics/angular/utility/standalone/rules_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('standalone utilities', () => {
3131
{
3232
name: projectName,
3333
standalone,
34+
routing: false,
3435
},
3536
host,
3637
);

tests/legacy-cli/e2e/tests/basic/rebuild.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default async function () {
5858
'src/app/app.module.ts': `
5959
import { BrowserModule } from '@angular/platform-browser';
6060
import { NgModule } from '@angular/core';
61+
import { RouterModule } from '@angular/router';
6162
6263
import { AppComponent } from './app.component';
6364
@@ -66,6 +67,7 @@ export default async function () {
6667
AppComponent
6768
],
6869
imports: [
70+
RouterModule,
6971
BrowserModule
7072
],
7173
providers: [],
@@ -95,14 +97,15 @@ export default async function () {
9597
'src/app/app.module.ts': `
9698
import { BrowserModule } from '@angular/platform-browser';
9799
import { NgModule } from '@angular/core';
98-
100+
import { RouterModule } from '@angular/router';
99101
import { AppComponent } from './app.component';
100102
101103
@NgModule({
102104
declarations: [
103105
AppComponent
104106
],
105107
imports: [
108+
RouterModule,
106109
BrowserModule
107110
],
108111
providers: [],

tests/legacy-cli/e2e/tests/build/lazy-load-syntax.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,14 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { appendToFile, prependToFile, readFile, replaceInFile, writeFile } from '../../utils/fs';
9+
import { readFile, replaceInFile, writeFile } from '../../utils/fs';
1010
import { ng } from '../../utils/process';
1111
import { updateJsonFile } from '../../utils/project';
1212

1313
export default async function () {
1414
const projectName = 'test-project';
1515
const appRoutingModulePath = 'src/app/app-routing.module.ts';
1616

17-
// Add app routing.
18-
// This is done automatically on a new app with --routing.
19-
await writeFile(
20-
appRoutingModulePath,
21-
`
22-
import { NgModule } from '@angular/core';
23-
import { Routes, RouterModule } from '@angular/router';
24-
25-
const routes: Routes = [];
26-
27-
@NgModule({
28-
imports: [RouterModule.forRoot(routes)],
29-
exports: [RouterModule]
30-
})
31-
export class AppRoutingModule { }
32-
`,
33-
);
34-
await prependToFile(
35-
'src/app/app.module.ts',
36-
`import { AppRoutingModule } from './app-routing.module';`,
37-
);
38-
await replaceInFile('src/app/app.module.ts', `imports: [`, `imports: [ AppRoutingModule,`);
39-
await appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>');
40-
4117
const originalAppRoutingModule = await readFile(appRoutingModulePath);
4218
// helper to replace loadChildren
4319
const replaceLoadChildren = async (route: string) => {

tests/legacy-cli/e2e/tests/build/library-with-demo-app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default async function () {
2525
`
2626
import {NgModule} from '@angular/core';
2727
import {BrowserModule} from '@angular/platform-browser';
28+
import {RouterModule} from '@angular/router';
2829
import {SecondaryModule} from 'mylib/secondary';
2930
import {AnotherModule} from 'mylib/another';
3031
@@ -35,6 +36,7 @@ export default async function () {
3536
AppComponent
3637
],
3738
imports: [
39+
RouterModule,
3840
SecondaryModule,
3941
AnotherModule,
4042
BrowserModule

tests/legacy-cli/e2e/tests/build/no-angular-router.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/legacy-cli/e2e/tests/build/prod-build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ export default async function () {
4545
await expectFileToMatch(`dist/test-project/${mainPath}`, bootstrapRegExp);
4646

4747
// Size checks in bytes
48-
verifySize(mainPath, 124000);
48+
verifySize(mainPath, 210000);
4949
}

0 commit comments

Comments
 (0)