For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /apis/app/runtime/router/memory-route.md.

Memory Route API

APIs exported from @modern-js/runtime/router for configuring and inspecting Memory Route on <ModernRoot />. Standard navigation APIs (useNavigate, useLocation, <Link>, useLoaderData, etc.) remain unchanged.

MemoryRouteProvider

Enables Memory Route for a <ModernRoot /> subtree.

import { MemoryRouteProvider } from '@modern-js/runtime/router';

<MemoryRouteProvider
  initialEntries={['/', '/detail/42']}
  initialIndex={1}
  basename="/shop"
>
  <ModernRoot />
</MemoryRouteProvider>;

Props

PropTypeDescription
entryPathstringInitial route path, such as '/detail/42?tab=info'.
initialEntriesMemoryRouteEntry[]Initial history stack.
initialIndexnumberActive index in initialEntries (defaults to the last entry).
initialStateunknownInitial location.state used with entryPath.
basenamestringRoute basename.
configMemoryRouterConfigShorthand or options object; explicit props take precedence.

ModernRoot memoryRoute

Enables or overrides Memory Route directly on a root component:

<ModernRoot memoryRoute="/beta" />

Resolution priority: props.memoryRoute > <MemoryRouteProvider> > router.memory.

useMemoryRoute

Returns the active Memory Route state inside a route component.

function useMemoryRoute(): {
  enabled: boolean;
  initialEntries?: MemoryRouteEntry[];
  initialIndex?: number;
  basename?: string;
};
import { useMemoryRoute } from '@modern-js/runtime/router';

const { enabled, basename } = useMemoryRoute();