Skip to content

Commit

Permalink
feat(angular): use provideRouter for standalone apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Sep 29, 2022
1 parent 56957cc commit aa466c9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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));"
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
NxJsonConfiguration,
parseJson,
readJson,
readProjectConfiguration,
readWorkspaceConfiguration,
updateJson,
} from '@nrwl/devkit';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -65,7 +63,7 @@ if (environment.production) {
bootstrapApplication(AppComponent${
routerModuleSetup
? `, {
providers: [importProvidersFrom(${routerModuleSetup})],
providers: [provideRouter(appRoutes, withEnabledBlockingInitialNavigation())],
}`
: ''
}).catch((err) => console.error(err));`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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));"
`;

Expand Down

0 comments on commit aa466c9

Please sign in to comment.