Memory Route
Memory Route keeps navigation history in memory without modifying the browser URL. It is useful for micro-frontends, embedded widgets, modals, or rendering multiple independent instances of an app on the same page.
Basic usage
For conventional (routes/) and config (modern.routes.ts) routes, enable router.memory in src/modern.runtime.ts:
To configure an initial history stack, initialIndex, state, or basename, pass an options object:
In multi-entry applications, use the function form defineRuntimeConfig(entryName => ...) to enable Memory Route only for specific entries.
Multiple instances
When mounting multiple root instances on the same page, configure each instance independently via <MemoryRouteProvider> or the memoryRoute prop:
Working with routes, Data Loaders, and SSR
Inside route components, existing APIs such as <Link>, useNavigate, useLocation, useParams, useLoaderData, and <Outlet> work as usual. Data Loaders and SSR are supported without extra changes.
If a component needs to check whether Memory Route is active, use useMemoryRoute().
Self-controlled routes
In self-controlled entries (src/App.tsx without routes/), router.memory does not apply. Use createMemoryRouter or <MemoryRouter> exported from @modern-js/runtime/router directly: