Getting Started: App Router
Embed a remote app's UI in a Next.js App Router page with RemoteIsland.
Embed an island from a remote app in a Next.js App Router page. To build the remote, see Writing an island remote.
Good to know: Requires Next.js 16 or 15 (>=15.5.28 <17), React 19 and Node 20.9 or newer.
cacheComponents needs Next 16 (Limits). To share client components
instead, see remote components.
Add an island to a page
Install the packages
npm install @next-federation/core @next-federation/next @next-federation/react server-only
npm install --save-exact react@19.3.1 react-dom@19.3.1Pin React to this exact version. Remove any caret that create-next-app left in package.json.
Wrap your Next config
Without the wrapper, the adapter fails with NF-017.
import { withNextFederation } from '@next-federation/next/config'
export default withNextFederation({
// your Next config, e.g. cacheComponents: true
})Define the federation
The config file imports nothing from Next.js, so nf-types can load it with plain Node.
import { defineFederation } from '@next-federation/core'
export const federation = defineFederation({
remotes: {
shop: { origin: process.env.SHOP_ORIGIN ?? 'https://shop.example.com' },
},
})The second file creates the island components.
import 'server-only'
import { createIslands } from '@next-federation/next/server'
import { federation } from './federation.config'
export { federation }
export const { RemoteIsland, preloadIsland, revalidateIsland } =
createIslands(federation)A remote is an origin, not a path. The host refuses redirects and fetches only from this origin.
Render the island
import { RemoteIsland } from '../lib/federation'
export default function Home() {
return (
<main>
<RemoteIsland
remote="shop"
island="ProductPanel"
props={{ sku: 'A1' }}
fallback={<p>loading product…</p>}
errorFallback={<p>product unavailable</p>}
/>
</main>
)
}props must be plain JSON, or the island throws NF-009. errorFallback shows when the remote fails, and the page still answers 200.
Open the CSP
Add each remote origin to script-src, connect-src and style-src. See CSP for a complete policy.
Good to know: Public islands are cached for islands.revalidate seconds.
Set revalidate on RemoteIsland to override it, or dynamic to fetch on
every request (Caching).
Show per-user content
A private island renders for the signed-in user. After the Identity setup, mark the island private.
<RemoteIsland
remote="shop"
island="MyOrders"
private
fallback={<p>loading orders…</p>}
errorFallback={<p>sign in to see your orders</p>}
/>Always set errorFallback. A visitor who is not signed in sees it. Without one, they see the loading text for good.
Put private content in the first HTML
A private island streams: the first HTML holds fallback. Add blocking to render the island in the first HTML instead, for crawlers or layouts that must not shift.
// With cacheComponents only: Next refuses `instant` without it.
export const instant = falseGood to know: blocking makes the whole route per-request and delays the
first byte until the remote answers. See the
costs.
Tune timeouts and retries
Each fetch has a timeoutMs budget (default 3000) and retries once. Set both for all remotes or per remote:
export const federation = defineFederation({
islands: { timeoutMs: 5000, retries: 2 },
remotes: {
shop: { origin: 'https://shop.example.com' },
reports: {
origin: 'https://reports.example.com',
timeoutMs: 8000,
retries: 0,
},
},
})See Timeouts and retries.
Next steps
Writing an island remote
Build the Vite remote that serves the island.
Identity
Private islands, signing keys and key rotation.
Caching
Static pages, ISR and cacheComponents with islands.
Limits
What islands cannot do and what they cost.
Runnable example: examples/next-app-router.