feat(angular): use provideRouter for standalone remote apps (#18468)

This commit is contained in:
Jakub Nabrdalik 2023-08-03 18:50:56 +02:00 committed by GitHub
parent e9d50af945
commit 64492ece8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 34 deletions

View File

@ -252,19 +252,13 @@ module.exports = withModuleFederation(config);
`;
exports[`MF Remote App Generator should generate the a remote setup for standalone components 1`] = `
"import { importProvidersFrom } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
"import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { RemoteEntryComponent } from './app/remote-entry/entry.component';
import { appRoutes } from './app/app.routes';
bootstrapApplication(RemoteEntryComponent, {
providers: [
importProvidersFrom(
RouterModule.forRoot(appRoutes, { initialNavigation: 'enabledBlocking' })
),
],
});
bootstrapApplication(RemoteEntryComponent, appConfig).catch((err) =>
console.error(err)
);
"
`;

View File

@ -35,11 +35,9 @@ export function fixBootstrap(tree: Tree, appRoot: string, options: Schema) {
const standaloneBootstrapCode = (
includeEnvironments: boolean = false
) => `import {importProvidersFrom} from "@angular/core";
import {bootstrapApplication} from "@angular/platform-browser";
import {RouterModule} from "@angular/router";
import {RemoteEntryComponent} from "./app/remote-entry/entry.component";
import {appRoutes} from "./app/app.routes";
) => `import {bootstrapApplication} from "@angular/platform-browser";
import {appConfig} from './app/app.config';
import {RemoteEntryComponent} from './app/remote-entry/entry.component';
${
includeEnvironments
? `import {enableProdMode} from '@angular/core';
@ -50,10 +48,6 @@ if(environment.production) {
`
: ``
}
bootstrapApplication(RemoteEntryComponent, {
providers: [
importProvidersFrom(
RouterModule.forRoot(appRoutes, {initialNavigation: 'enabledBlocking'})
)
]
});`;
bootstrapApplication(RemoteEntryComponent, appConfig).catch((err) =>
console.error(err)
);`;

View File

@ -357,24 +357,18 @@ describe('Init MF', () => {
// ASSERT
expect(tree.read('apps/ng14/src/bootstrap.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import { importProvidersFrom } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
"import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { RemoteEntryComponent } from './app/remote-entry/entry.component';
import { appRoutes } from './app/app.routes';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
bootstrapApplication(RemoteEntryComponent, {
providers: [
importProvidersFrom(
RouterModule.forRoot(appRoutes, { initialNavigation: 'enabledBlocking' })
),
],
});
bootstrapApplication(RemoteEntryComponent, appConfig).catch((err) =>
console.error(err)
);
"
`);
});