Skip to content

Angular MFE remote configuration: expose routes

You will turn orders-mfe from Project setup into a useful remote. It will expose a standalone Routes array (an order list and an order detail page) under the key ./routes, keep its own services inside that route tree, still run on its own for its team, and publish a remoteEntry.json that the OrdersPortal shell loads at runtime. The shell side is on Host application setup.

  • The workspace from Project setup, with orders-mfe initialized as a Native Federation remote on port 4201.
  • Toolchain versions from Prerequisites.

How to run the samples: every TypeScript file below belongs in projects/orders-mfe/src/app/ of that workspace. Build with npx ng build orders-mfe and run with npx ng serve orders-mfe. All samples on this page were built with Angular 22.2 and @angular-architects/native-federation 22.2.5, and rendered in headless Chrome.

A remote’s exposed modules are a public API between teams. You can expose almost any file, but three shapes are common:

Exposed shape Shell loads it with Use when
A Routes array loadChildren The remote owns a whole business area with several pages. This is the default choice.
A standalone component loadComponent, or dynamic creation with ViewContainerRef The remote provides one page or one widget placed by the shell.
A web component (--webcomponent at init) A custom element tag The host is not Angular, or must not share Angular’s version with the remote.

Exposing routes gives the remote team the most freedom: they can add, rename and lazy-load child pages without changing the shell, as long as the entry path stays stable. The schematic’s default exposes entry (./Component pointing at the root App) is a placeholder; exposing the root component pulls the remote’s whole application shell into the host, which is rarely what you want.

Step 2: Write the feature as standalone routes

Section titled “Step 2: Write the feature as standalone routes”

Create a small store, two pages and the routes file. The store is provided at route level, so it exists only while the user is inside the orders area and the shell never has to register it.

orders/orders-store.ts
import { Injectable, signal } from '@angular/core';
export interface OrderSummary {
id: string;
customer: string;
total: number;
}
// Provided at route level in ORDERS_ROUTES, so the shell never has to know about it.
@Injectable()
export class OrdersStore {
private readonly orders = signal<OrderSummary[]>([
{ id: 'ord-1001', customer: 'Northwind Test', total: 120 },
{ id: 'ord-1002', customer: 'Example Ltd', total: 75 },
]);
readonly all = this.orders.asReadonly();
}
orders/order-list.ts
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { RouterLink } from '@angular/router';
import { OrdersStore } from './orders-store';
@Component({
selector: 'orders-order-list',
imports: [RouterLink],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<h2>Orders</h2>
<ul>
@for (order of store.all(); track order.id) {
<li><a [routerLink]="[order.id]">{{ order.id }}</a> {{ order.customer }}: {{ order.total }}</li>
}
</ul>
`,
})
export class OrderList {
protected readonly store = inject(OrdersStore);
}
orders/order-detail.ts
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
@Component({
selector: 'orders-order-detail',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `<h2>Order {{ orderId() }}</h2>`,
})
export class OrderDetail {
// Bound from the :orderId route parameter by withComponentInputBinding().
readonly orderId = input.required<string>();
}
orders/orders.routes.ts
import { Routes } from '@angular/router';
import { OrdersStore } from './orders-store';
export const ORDERS_ROUTES: Routes = [
{
path: '',
providers: [OrdersStore],
children: [
{ path: '', loadComponent: () => import('./order-list').then((m) => m.OrderList) },
{ path: ':orderId', loadComponent: () => import('./order-detail').then((m) => m.OrderDetail) },
],
},
];

Two details matter for federation:

  • Relative links. [routerLink]="[order.id]" is relative to the current route, so it works whether the routes are mounted at /orders in the remote or at /orders (or any other path) in the shell. Avoid absolute links such as /orders/ord-1001 inside a remote.
  • Lazy child pages. Each page is its own chunk, so the shell downloads order-detail only when someone opens an order.

The remote’s own app.routes.ts mounts the same routes, so the orders team can develop at http://localhost:4201/orders without the shell:

app.routes.ts
import { Routes } from '@angular/router';
// Standalone mode: the remote runs on its own at http://localhost:4201/orders
export const routes: Routes = [
{ path: '', pathMatch: 'full', redirectTo: 'orders' },
{ path: 'orders', loadChildren: () => import('./orders/orders.routes').then((m) => m.ORDERS_ROUTES) },
];
app.config.ts
import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core';
import { provideRouter, withComponentInputBinding } from '@angular/router';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [provideBrowserGlobalErrorListeners(), provideRouter(routes, withComponentInputBinding())],
};

Replace the generated app.html with <router-outlet />.

This is the most misunderstood part of remotes: app.config.ts does not run when the shell loads the remote. Only the exposed file and what it imports are used. Anything a page needs must be either provided in the exposed routes (as OrdersStore is) or provided by the shell as part of a documented contract. In this example, withComponentInputBinding() is configured in both applications because OrderDetail relies on it; the shell’s side is on Host application setup.

Verify: npx ng serve orders-mfe, then open http://localhost:4201/orders/ord-1001. The page shows “Order ord-1001”.

Step 4: Expose the routes in federation.config.mjs

Section titled “Step 4: Expose the routes in federation.config.mjs”

Edit projects/orders-mfe/federation.config.mjs. The generated file already contains sensible sharing defaults; change only exposes:

import {
withNativeFederation,
fromPackageJson,
} from '@angular-architects/native-federation/config';
export default withNativeFederation({
name: 'orders-mfe',
exposes: {
'./routes': './projects/orders-mfe/src/app/orders/orders.routes.ts',
},
shared: fromPackageJson({
singleton: true,
strictVersion: true,
requiredVersion: 'auto',
build: 'package',
}).patch(['@angular/*'], { includeSecondaries: { keepAll: true } }),
skip: ['rxjs/ajax', 'rxjs/fetch', 'rxjs/testing', 'rxjs/webSocket'],
features: {
denseChunking: true,
denseExternals: true,
strictImports: false,
},
});

What the fields mean:

  • name must match the key the shell uses in federation.manifest.json (orders-mfe).
  • exposes maps a public key (./routes) to a source file. The key is the contract; the file path is private and can change freely.
  • shared with fromPackageJson(...) shares every dependency in package.json. singleton: true asks for one copy across shell and remotes; strictVersion: true records that the version must satisfy the range (whether the runtime enforces it is shown in Advanced concepts; with default options it does not, so the pipeline check is what protects you); requiredVersion: 'auto' takes the range from package.json. The .patch(['@angular/*'], ...) call shares every Angular secondary entry point so all builds publish the same set.
  • skip excludes packages or entry points you never want shared.
  • features turns on the adapter’s newer chunking options; keep the generated defaults unless the Native Federation documentation for your version says otherwise.

The adapter’s configuration helpers also include shareAll, autoShareScope, shareAngularLocales and mappingsFromWorkspace (for sharing workspace libraries such as a design system). The older share helper still exists but is marked deprecated in the 22.2.5 typings: “Use fromPackageJson().only([...]).override({...}) instead”. Older articles that call share({...}) therefore produce a deprecation warning in your editor. Advanced concepts covers when to share what.

Verify: npx ng build orders-mfe, then grep -o '"key": "[^"]*"' dist/orders-mfe/browser/remoteEntry.json prints "key": "./routes".

The remote’s entry point initializes federation before importing the bootstrap file:

// projects/orders-mfe/src/main.ts (generated)
import { initFederation } from '@angular-architects/native-federation';
initFederation(
{},
{
hostRemoteEntry: { url: './remoteEntry.json' },
},
)
.catch((err) => console.error(err))
.then((_) => import('./bootstrap'))
.catch((err) => console.error(err));

A remote has no remotes of its own (the empty {}), but in standalone mode it still needs federation initialized so its shared packages resolve through the import map. When the shell loads the remote, this file is not executed at all.

Verify: grep -c "@angular/core" projects/orders-mfe/src/main.ts prints 0, and http://localhost:4201/orders still renders the order list under ng serve.

Step 6: Build and inspect remoteEntry.json

Section titled “Step 6: Build and inspect remoteEntry.json”
Terminal window
npx ng build orders-mfe

dist/orders-mfe/browser/remoteEntry.json now lists the exposed key and every shared package with the version it was built against. An excerpt:

{
"$version": "v4",
"name": "orders-mfe",
"shared": [
{
"requiredVersion": "^22.2.0",
"singleton": true,
"strictVersion": true,
"version": "22.2.6",
"packageName": "@angular/core"
}
]
}

This file is what the shell negotiates against, and it is what the remote’s pipeline checks before deploying: the exposed keys and the @angular/core version must match what the shell expects (Azure deployment has the script). Do not rely on the browser to catch a mismatch. With the 22.2.5 runtime defaults, a remote built with Angular 22.1 was loaded with its own copy of Angular and failed only when its first component rendered; Advanced concepts shows the real output.

Step 7: Make the remote loadable from another origin

Section titled “Step 7: Make the remote loadable from another origin”

In production the shell (https://portal.example.test) and the remote (https://orders.example.test) usually live on different origins. The browser fetches remoteEntry.json and the module files with CORS, so the remote’s host must send an Access-Control-Allow-Origin header naming the shell’s origin. During ng serve the dev server already answers with Access-Control-Allow-Origin: *, which is why local testing works without extra setup; for deployed remotes, configure it on the hosting platform, as shown in Azure deployment. Do not use * for remotes that serve anything user-specific.

Also settle the URL now. This section serves each remote from a stable root URL (https://orders.example.test/remoteEntry.json): a release replaces the files behind it, the shell’s manifest never changes for a normal release, and a rollback redeploys the previous build. The .js and .css files carry content hashes, so a host can cache them forever; remoteEntry.json, importmap.json, index.html and anything copied from public/ (such as favicon.ico or staticwebapp.config.json) keep fixed names and must be revalidated; why open tabs still need the previous release’s hashed files, and the versioned-path alternative, are covered in Azure deployment.

Verify: curl -s -D - -o /dev/null -H "Origin: http://localhost:4200" http://localhost:4201/remoteEntry.json | grep -i access-control prints Access-Control-Allow-Origin: * under ng serve.

npx ng serve orders-mfe serves the orders area on its own at http://localhost:4201/orders, and http://localhost:4201/remoteEntry.json returns the metadata above with ./routes exposed. The shell can now load ORDERS_ROUTES by name.

  • “NullInjectorError: No provider for OrdersStore” only when loaded in the shell. The service was provided in the remote’s app.config.ts. Move it into the exposed routes’ providers array or make it providedIn: 'root'.
  • The detail page shows an empty order ID inside the shell. The shell’s router lacks withComponentInputBinding(). Either add it to the shell (and document it as part of the contract) or read the parameter with inject(ActivatedRoute) in the remote.
  • The shell logs a 404 for remoteEntry.json. The remote was not built or served, or the manifest URL is wrong. Open the URL directly in the browser.
  • Inside the shell the orders area stays empty and the console shows NG0203 from an _angular_core file on the remote’s origin. The remote was built with a different Angular minor and loaded its own copy of Angular. Align the versions and add the contract check to the remote’s pipeline; see Advanced concepts.
  • Links inside the remote jump to the shell’s root. They are absolute (/orders/...). Make them relative.

Load ./routes from the shell in Host application setup, then test both together in Local testing.