Renders a page of the new frontend system with TanStack Router, scoped to the page's own path.
Browser history belongs to the app. This package never writes to
window.history. It only scopes TanStack Router to the page it renders, so
programmatic back, forward, and go traverse the app-owned history.
This package is part of scoped plugin routing, RFC #33603.
TanStack Router is a peer dependency, so install it alongside the adapter:
cd <package-dir> # if within a monorepo
yarn add @backstage/frontend-adapter-tanstack-router @tanstack/react-router@1.131.2 @tanstack/history@1.131.2
The adapter pins @tanstack/react-router to 1.131.2, the latest release
verified to pass strict dependency type checking with React 18 without a
package patch. Newer releases through 1.170.36 have declaration errors
in TanStack Router or its router-core dependency.
This issue may already be fixed in a newer TanStack Router release when you read this. Check the latest releases and the adapter's current peer dependency range before choosing a version.
Render TanStackPageRouter inside the lazily loaded component of the page whose
content should get the context:
import { PageBlueprint } from '@backstage/frontend-plugin-api';
const toolsPage = PageBlueprint.make({
params: {
path: '/tools',
loader: () => import('./components/ToolsPage').then(m => <m.ToolsPage />),
},
});
The adapter belongs in the lazily loaded component module. Wrap the page's existing JSX directly; only hooks that consume this router need to be in a child beneath it.
import { TanStackPageRouter } from '@backstage/frontend-adapter-tanstack-router';
export function ToolsPage() {
return (
<TanStackPageRouter>
{/* Existing page JSX and local routes go here. */}
</TanStackPageRouter>
);
}
TanStackPageRouter renders the content it is given through a catch-all route.
That covers pages that render the content they are handed without routing inside
it.
The adapter is scoped where the page component renders it. TanStack Router publishes its own React context, so it can nest with adapters from other libraries. The app also retains a root React Router v6 projection for shared components; page content using v6 retains implicit page-relative compatibility. An explicit adapter migrates that content away from the fallback.
Rendering it in a sub-page's component scopes it to that sub-page, because the sub-page's app node determines its routing scope. Sibling tabs may declare different libraries, or none at all.
Declare it in the component that owns the page or sub-page route mount. An
EntityContentBlueprint tab, a card, or anything else filling a region of
another page already renders inside the adapter that page declared, one
route match deeper. A second adapter there re-scopes to the page's own mount and
drops the tab's match, so relative targets in that content resolve from the page
instead of from the tab.
Scoping needs two things: a page mount, saying which part of the URL belongs to
the page, and a registered AppHistoryApi to project a history from. With
either missing, this adapter renders its children untouched and asks nothing of
the surrounding app — no API provider, no framework context. No route tree is
built, and createRouter is never called.
That passthrough is what lets a plugin shipping for both frontend systems wrap a
shared component in the adapter. The old frontend system supplies neither half,
so the wrap is invisible there rather than a crash. The same holds in a plugin's
own render() unit tests, which stand up no app at all. A router built with
createTanStackPageRouter behaves the same way.
To route with a nested TanStack tree of your own, build the page router from
that tree with createTanStackPageRouter. Render TanStackPageContent
wherever in the tree the Backstage page element belongs:
import {
TanStackPageContent,
createTanStackPageRouter,
} from '@backstage/frontend-adapter-tanstack-router';
import {
Outlet,
createRootRoute,
createRoute,
createRouter,
} from '@tanstack/react-router';
import { ToolDetails } from './ToolDetails';
const ToolsPageRouter = createTanStackPageRouter({
createRouter: ({ history, routePaths }) => {
const rootRoute = createRootRoute({ component: Outlet });
const routeTree = rootRoute.addChildren(
routePaths.map(routePath => {
const pageRoute = createRoute({
getParentRoute: () => rootRoute,
path: routePath,
component: () => (
<>
<TanStackPageContent />
<Outlet />
</>
),
});
const detailsRoute = createRoute({
getParentRoute: () => pageRoute,
path: 'details',
component: ToolDetails,
});
return pageRoute.addChildren([detailsRoute]);
}),
);
return createRouter({ routeTree, history });
},
});
export function ToolsPage() {
return (
<ToolsPageRouter>
<h1>Tools</h1>
</ToolsPageRouter>
);
}
Going through the factory keeps TanStack types out of the framework's public contract, so they stay inside this package and your own plugin.
Paths starting with / are absolute from the app root, without the deployment
basename. Route-ref destinations work unchanged through this adapter's native
navigation APIs and through BUI controls, including navigation to other plugins.
The adapter supplies RoutingProvider from @backstage/frontend-plugin-api/routing.
useRoutingIntegration, RouterLink, and BUI controls resolve relative targets using
the routing library at the consuming control's route scope. Other component
libraries can integrate through the same public hook; the adapter has no BUI
runtime dependency. Outside an adapter, framework routing accepts only app-absolute
paths, empty/query/hash targets, and external URLs.
useBlocker only intercepts navigation that starts inside this page. It cannot
see navigation coming from elsewhere in the app, because the app's history API
has no shared blocker contract.
Custom AppHistoryApi implementations must expose their updated location
snapshot synchronously when handling push or replace navigation. TanStack
notifies its subscribers immediately after the host handles the request;
later host notifications for that write are ignored. Back, forward, and go
notify subscribers when the host emits the resulting location, which can be
asynchronous.
The public AppHistorySnapshot optionally exposes entry identity and stack
position through entry, index, and length. It does not report traversal
completion or operation correlation.
Without this optional entry metadata, the
adapter exposes one synthetic slot: history.length is 1, __TSR_index is
0, and both history.canGoBack() and TanStack's useCanGoBack() return false.
Back, forward, and go still delegate to the host even with this conservative
back-availability result.
TanStack supplies its native push and replace actions, blockers, and state
fields. Host updates without entry metadata are reported as GO with a zero
delta. Keys supplied by TanStack can remain in the host's state, but hosts
without entry metadata cannot reliably identify entries created elsewhere in
the app. Entry-based scroll restoration therefore lacks full fidelity with
these custom histories. The adapter does not infer a second history stack from
URLs, which can be identical for different entries.
TanStack Router adapter for Backstage scoped plugin routing.