Skip to content

Commit

Permalink
feat(angular): use provideRouter for standalone remote apps (#18468)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnabrdalik committed Aug 3, 2023
1 parent e9d50af commit 64492ec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
"
`;
Expand Down
18 changes: 6 additions & 12 deletions packages/angular/src/generators/setup-mf/lib/fix-bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -50,10 +48,6 @@ if(environment.production) {
`
: ``
}
bootstrapApplication(RemoteEntryComponent, {
providers: [
importProvidersFrom(
RouterModule.forRoot(appRoutes, {initialNavigation: 'enabledBlocking'})
)
]
});`;
bootstrapApplication(RemoteEntryComponent, appConfig).catch((err) =>
console.error(err)
);`;
16 changes: 5 additions & 11 deletions packages/angular/src/generators/setup-mf/setup-mf.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
"
`);
});
Expand Down

1 comment on commit 64492ec

@vercel
Copy link

@vercel vercel bot commented on 64492ec Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.