Lesson 5 of 9 · 23m
Routing Across a Federated Frontend
The shell owns top-level navigation, remotes own internal routes, and the URL becomes the stable contract between independently deployed applications.
Routing is where micro-frontends stop being independent experiments and become one product. Users do not care which team owns /checkout/payment; they expect back, refresh, deep links, and browser history to work. If every remote owns the whole URL bar, you have a distributed fight over global mutable state.
The durable rule is simple: the shell owns top-level route allocation; remotes own routes below their prefix.
Allocate prefixes like API namespaces
/catalog/* -> discovery remote
/product/* -> merchandising remote
/cart -> transactions remote
/checkout/* -> transactions remote
/account/* -> identity remoteA remote should never reach outside its prefix. If checkout needs to send the user to account settings, it asks the shell to navigate or emits a navigation intent. Direct manipulation of window.location inside a remote is sometimes necessary for full transitions, but it should be an explicit edge case, not the integration mechanism.
Use the platform history, carefully
Inside a React shell, the integration often looks like this:
function CheckoutRemoteHost() {
const navigate = useNavigate();
return <CheckoutApp basePath="/checkout" onNavigate={navigate} onExternalNavigate={navigate} />;
}The remote receives basePath and reports navigation upward. Internally it may use its own router, but it treats the shell as the authority for the address bar.
Deep links are part of the contract
A URL like /checkout/payment?cart=crt_92fj&step=2 must be meaningful after refresh. That means remote bootstrap code cannot assume the user entered through /checkout. Test deep links first; they reveal hidden assumptions about initialization order and state ownership.
Avoid route-dependent runtime magic
This pattern is fragile:
if (location.pathname.includes("checkout")) {
import("./checkoutRemote");
}It scatters ownership across conditionals and breaks when paths change. Prefer declarative route registration:
const routes = [{ path: "/checkout/*", remote: "checkout", boundary: CheckoutErrorBoundary },
{ path: "/account/*", remote: "identity", boundary: AccountErrorBoundary }];Now the shell can preload, trace, and isolate failures consistently.
Navigation state belongs in the URL when it is shareable
Tabs, filters, pagination, and selected entities should be query parameters when users might bookmark or share them. Ephemeral interaction state — focus, hover, transient wizard progress — can stay inside the remote. Do not let the shell mirror every remote detail just to make navigation work; that recreates coupling one prop at a time.
Field notes
- The URL is a public API. Changing it is a breaking change regardless of which team owns the code.
- Test refresh, back, forward, copy-paste, and expired-session flows for every remote prefix.
- Beware routers nested inside routers both listening to popstate; one authority must translate events.
- Route ownership should be visible in infrastructure — CDN rules, observability tags, and error dashboards — not just in source code.
Was this lesson helpful?