From aa466c94efb26482a279d96bd0ee85ec7e1eab37 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Wed, 14 Sep 2022 10:03:16 +0100 Subject: [PATCH] feat(angular): use provideRouter for standalone apps --- .../application/__snapshots__/application.spec.ts.snap | 6 +++--- .../src/generators/application/application.spec.ts | 1 + .../application/lib/convert-to-standalone-app.ts | 8 +++----- .../src/generators/host/__snapshots__/host.spec.ts.snap | 6 +++--- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap index f741a1c8c2ee2..f40894cbd4691 100644 --- a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap +++ b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`app --standalone should generate a standalone app correctly with routing 1`] = ` -"import { enableProdMode, importProvidersFrom } from '@angular/core'; +"import { enableProdMode } from '@angular/core'; import { bootstrapApplication } from '@angular/platform-browser'; -import { RouterModule } from '@angular/router'; +import { provideRouter, withNonEnabledBlockingInitialNavigation } from '@angular/router'; import { AppComponent } from './app/app.component'; import { environment } from './environments/environment'; import { appRoutes } from './app/app.routes'; @@ -13,7 +13,7 @@ if (environment.production) { } bootstrapApplication(AppComponent, { - providers: [importProvidersFrom(RouterModule.forRoot(appRoutes, {initialNavigation: 'enabledBlocking'}))], + providers: [provideRouter(appRoutes, withEnabledBlockingInitialNavigation())], }).catch((err) => console.error(err));" `; diff --git a/packages/angular/src/generators/application/application.spec.ts b/packages/angular/src/generators/application/application.spec.ts index eb2d9ec61c8b8..65ab4aeec7da1 100644 --- a/packages/angular/src/generators/application/application.spec.ts +++ b/packages/angular/src/generators/application/application.spec.ts @@ -5,6 +5,7 @@ import { NxJsonConfiguration, parseJson, readJson, + readProjectConfiguration, readWorkspaceConfiguration, updateJson, } from '@nrwl/devkit'; diff --git a/packages/angular/src/generators/application/lib/convert-to-standalone-app.ts b/packages/angular/src/generators/application/lib/convert-to-standalone-app.ts index 0ff0559d8feb2..f7a9f1a75f1fc 100644 --- a/packages/angular/src/generators/application/lib/convert-to-standalone-app.ts +++ b/packages/angular/src/generators/application/lib/convert-to-standalone-app.ts @@ -45,13 +45,11 @@ function updateMainEntrypoint( const standaloneComponentMainContents = ( routerModuleSetup -) => `import { enableProdMode${ - routerModuleSetup ? `, importProvidersFrom` : `` -} } from '@angular/core'; +) => `import { enableProdMode } from '@angular/core'; import { bootstrapApplication } from '@angular/platform-browser';${ routerModuleSetup ? ` -import { RouterModule } from '@angular/router'` +import { provideRouter, withNonEnabledBlockingInitialNavigation } from '@angular/router'` : `` }; import { AppComponent } from './app/app.component'; @@ -65,7 +63,7 @@ if (environment.production) { bootstrapApplication(AppComponent${ routerModuleSetup ? `, { - providers: [importProvidersFrom(${routerModuleSetup})], + providers: [provideRouter(appRoutes, withEnabledBlockingInitialNavigation())], }` : '' }).catch((err) => console.error(err));`; diff --git a/packages/angular/src/generators/host/__snapshots__/host.spec.ts.snap b/packages/angular/src/generators/host/__snapshots__/host.spec.ts.snap index 988d9a4718948..fcd1665389329 100644 --- a/packages/angular/src/generators/host/__snapshots__/host.spec.ts.snap +++ b/packages/angular/src/generators/host/__snapshots__/host.spec.ts.snap @@ -19,9 +19,9 @@ module.exports = withModuleFederation(config);" `; exports[`Host App Generator should generate a host with remotes using standalone components 1`] = ` -"import { enableProdMode, importProvidersFrom } from '@angular/core'; +"import { enableProdMode } from '@angular/core'; import { bootstrapApplication } from '@angular/platform-browser'; -import { RouterModule } from '@angular/router'; +import { provideRouter, withNonEnabledBlockingInitialNavigation } from '@angular/router'; import { AppComponent } from './app/app.component'; import { environment } from './environments/environment'; import { appRoutes } from './app/app.routes'; @@ -31,7 +31,7 @@ if (environment.production) { } bootstrapApplication(AppComponent, { - providers: [importProvidersFrom(RouterModule.forRoot(appRoutes, {initialNavigation: 'enabledBlocking'}))], + providers: [provideRouter(appRoutes, withEnabledBlockingInitialNavigation())], }).catch((err) => console.error(err));" `;