Skip to content

feat(frontend): add scoped routing with implicit v6 compatibility - #34830

Merged
Rugvip merged 82 commits into
backstage:masterfrom
schultzp2020:feature/33603-scoped-plugin-routing-clean
Nov 11, 2026
Merged

Rugvip merged 82 commits into
backstage:masterfrom
schultzp2020:feature/33603-scoped-plugin-routing-clean

Conversation

@schultzp2020

@schultzp2020 schultzp2020 commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Hey, I just made a Pull Request!

Implements RFC #33603.

This gives the new frontend system one app-owned browser history while allowing pages and sub-pages to choose React Router v6, React Router v7, TanStack Router, or no routing library. Different adapters can coexist without creating competing browser histories. Existing React Router v6 pages keep working through implicit compatibility, so plugin migration can happen separately.

This diagram shows ownership rather than React component nesting: adapters project the app history into their own router contexts.

flowchart TD
  Browser["Browser history"] <--> History["AppHistoryApi<br/>single history authority"]
  History --> Routes["Framework matching<br/>extension route tree"]
  Routes --> Scope["Matched page or sub-page"]
  Scope --> V6["React Router v6<br/>explicit adapter or implicit compatibility"]
  Scope --> V7["React Router v7<br/>explicit adapter"]
  Scope --> TanStack["TanStack Router<br/>explicit adapter"]
  Scope --> Routerless["Framework routing only<br/>no adapter declaration"]
  History -. "location and navigation" .-> V6
  History -. "location and navigation" .-> V7
  History -. "location and navigation" .-> TanStack
  History --> BUI["BUI host hook<br/>navigate, createHref, pathname"]
  Scope -. "consumer route ancestry" .-> BUI
  History --> Chrome["Temporary React Router v6<br/>app-chrome projection"]
Loading

What changed

  • AppHistoryApi provides navigate and createHref, including numeric back/forward traversal, and exposes app history as a synchronous external store through getSnapshot() and subscribe(listener). Cached immutable snapshots contain location and optional action, entry, and length metadata; the store functions can be passed directly to useSyncExternalStore.
  • The app writes native browser history and observes Navigation API entry changes where available, with popstate and hashchange fallback. Adapters delegate navigation to that history.
  • One matched extension branch supplies route references, parameters, mount ancestry, and content selection, using React Router v6-compatible matching. Parents retain ownership of rendering their children.
  • Pages and sub-pages can render ReactRouterV6PageRouter, ReactRouterV7PageRouter, or TanStackPageRouter inside their lazily loaded React components. createTanStackPageRouter also supports plugin-owned TanStack route trees.
  • useAppLocation and useAppSearchParams read and update the app location and query without requiring a page router. Shared route-reference hooks read framework matches without consuming the implicit compatibility context.
  • BUIProvider accepts a useNavigation hook returning navigate, createHref, and pathname. Adapters supply the component-library-neutral NavigationProvider; navigation binds at each consumer's route scope, so relative links use the nearest adapter and active tabs/header links respect the deployment basename.
  • Links preserve native modified clicks, downloads, non-self targets, and external URLs. Browser-executable javascript:, data:, and vbscript: targets become inert.

Compatibility and migration

Existing new frontend pages do not need to migrate immediately. Pages that consume React Router v6 context without an explicit adapter receive implicit compatibility backed by the same app history, including route parameters, relative links, and nested routes. Development builds warn once per extension per app history instance when that fallback is consumed.

Pages using only framework routing, or no routing at all, need no adapter declaration and receive no migration warning. Converted legacy routes receive the v6 adapter through conversion. Inside an adapter, page-local Link, useNavigate, useParams, and <Routes> continue to work.

Keep adapter imports in the lazy page module and wrap the page’s existing JSX directly. Blueprint loaders only import and render that component. Components that use only Backstage routing need no wrapper.

For absolute or cross-plugin navigation, resolve route refs with useRouteRef and use useAppNavigate or useAppHref. RouteLink was removed: use useRouteRef with BUI Link for standard links, or RouterLink and useNavigation for contextual navigation and custom UI integration. Framework hooks require app-absolute paths; contextual navigation follows the nearest adapter for relative targets. Shared hooks fall back to React Router in the old frontend system, which retains its existing root-router support and React 17 compatibility. Plugin adoption is in #35692.

In the new frontend system, RouterBlueprint and the app/root router input are removed, and converted legacy components.Router overrides are rejected. Remove plain BrowserRouter overrides, move global providers to AppRootWrapperBlueprint, and supply custom history through an appHistoryApiRef factory. Upstream-rebase reconciliation aligns app creation with prepareSpecializedApp, updates routing tests for the removal of session-state reuse, and refreshes test-utility API reports; default history remains lazy and is created on first use.

The temporary v6 app-chrome projection owns no browser history. Its removal depends on routerless chrome coverage and dependency enforcement; page adapter support is independent of that removal.

Demo and remaining limits

The companion migration PR adds mixed-adapter tabs, nested routes, implicit compatibility, and routerless content at /nfs-routing-demo, /nfs-routing-demo-v7, and /nfs-routing-demo-tanstack.

Regression coverage includes framework history and external-store snapshots, location/query and routing hooks, legacy fallback, adapter navigation, and routing test utilities. The latest changes update these tests and API reports; earlier test counts and local validation results are not presented as validation of the rebased head.

Navigation blockers remain local to the routing library; there is no app-wide blocker contract. TanStack blockers cover local push/replace, not numeric traversal. Custom histories without entry metadata have limited back-availability reporting and entry-based restoration, while traversal still delegates to the host.

Normal app teardown releases browser listeners. Hot reload can create a replacement app without unmounting the previous root, leaving its listener attached until reload.

The adapter pins @tanstack/react-router 1.131.2, which needs no React 18 declaration workaround; downstream apps must use exactly 1.131.2 to satisfy the router peer (the history peer allows ^1.131.2).

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

Copilot AI review requested due to automatic review settings July 10, 2026 21:17
@schultzp2020
schultzp2020 requested review from a team and backstage-service as code owners July 10, 2026 21:17
@github-actions github-actions Bot added area:documentation Improvements or additions to documentation area:catalog Related to the Catalog Project Area area:techdocs Related to the TechDocs Project Area area:scaffolder Everything and all things related to the scaffolder project area area:search labels Jul 10, 2026
@backstage-goalie

backstage-goalie Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Important

This PR includes changes that affect public-facing API. Please ensure you are adding/updating documentation for new features or behavior.

Missing Changesets

The following package(s) are changed by this PR but do not have a changeset:

  • @backstage/core-plugin-api

See CONTRIBUTING.md for more information about how to add changesets.

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/core-app-api packages/core-app-api patch v1.20.7-next.1
@backstage/core-compat-api packages/core-compat-api minor v0.5.17-next.1
@backstage/core-plugin-api packages/core-plugin-api none v1.12.12-next.1
@backstage/frontend-adapter-react-router-v6 packages/frontend-adapter-react-router-v6 minor v0.1.0
@backstage/frontend-adapter-react-router-v7 packages/frontend-adapter-react-router-v7 minor v0.1.0
@backstage/frontend-adapter-tanstack-router packages/frontend-adapter-tanstack-router minor v0.1.0
@backstage/frontend-app-api packages/frontend-app-api patch v0.17.0-next.1
@backstage/frontend-defaults packages/frontend-defaults patch v0.5.8-next.1
@internal/frontend packages/frontend-internal none v0.0.26-next.1
@backstage/frontend-plugin-api packages/frontend-plugin-api minor v0.19.0-next.1
@backstage/frontend-test-utils packages/frontend-test-utils minor v0.7.0-next.1
@backstage/repo-tools packages/repo-tools patch v0.19.3-next.0
@backstage/ui packages/ui minor v0.19.0
@backstage/plugin-app-react plugins/app-react minor v0.3.0-next.1
@backstage/plugin-app plugins/app minor v0.6.0-next.1
@backstage/plugin-catalog plugins/catalog patch v2.0.11-next.1

@backstage-goalie backstage-goalie Bot added size:huge Huge pull requests receive a lower priority for reviews. waiting-for:review The PR needs a review and will be visible in the review queue unless already assigned an owner. labels Jul 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings July 10, 2026 22:42
@schultzp2020
schultzp2020 force-pushed the feature/33603-scoped-plugin-routing-clean branch from 2fd9992 to 8bd0357 Compare July 10, 2026 22:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings July 10, 2026 22:49
@schultzp2020
schultzp2020 force-pushed the feature/33603-scoped-plugin-routing-clean branch from e7e8647 to 5ca70ae Compare July 10, 2026 22:49
schultzp2020 and others added 9 commits November 9, 2026 10:18
…zation

Re-applies 9bac36e on top of the scoped routing app root: root
elements are keyed by their extension ID and rendered in a single fixed
position, so finalization no longer remounts the app content.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Signed-off-by: Paul Schultz <[email protected]>
Rugvip and others added 14 commits November 10, 2026 08:15
frontend-app-api: preserve compatibility for older routing blueprints
…ckages

frontend-adapter-react-router-v6: rename routing adapter packages
Covers the review findings from the scoped-routing merge: the routing
compatibility seam applied to v1 named outputs, middleware-replaced
outputs, and route refs; empty route mounts with an omitted or null
react element; direct history navigation that unmounts the navigating
page and navigation callbacks retained past unmount; and the
AppRouteSwitch behavior for an empty route table and a crashing
not-found page.

Signed-off-by: Paul Schultz <[email protected]>
frontend-app-api: fix routing compatibility and app replacement
const namedSegments = hasSplat ? segments.slice(0, -1) : segments;

for (const segment of namedSegments) {
const param = segment.match(/^:([\w-]+)(\?)?(.*)$/);

@Rugvip Rugvip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is time 🤯

Biggest change we've shipped.

Leaving old comments around to handle in followups if they still apply.


Added `TanStackPageRouter` for page-scoped TanStack routing with app-owned history. Use `createTanStackPageRouter` and `TanStackPageContent` to integrate a plugin-owned route tree.

Install `@tanstack/[email protected]` and `@tanstack/[email protected]` alongside the adapter. Without a page mount or app history, the adapter renders children unchanged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just make these direct deps instead? Given how specific the adapter is it seems low risk and ofc a nice utility

import { ReactRouterV6PageRouter } from '@backstage/plugin-app-react-router-v6';

await renderInTestApp(<EntityHeader />, {
router: ReactRouterV6PageRouter,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit redundant, as opposed to just expecting it to be wrapping the subject instead? Or do we need to hook it up in a specific way and does it need specific props in that case?

routing. They work on every page, whichever library it uses and on pages that
use none. Try them before reaching for anything else on this page.

Existing new frontend system pages retain implicit React Router v6 routing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

```

The options support `replace` and `state`. This declaration belongs to your app;
BUI does not set React Aria's global router types for plugins.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: how come?

"@backstage/types": "workspace:^",
"@backstage/ui": "workspace:^",
"@backstage/version-bridge": "workspace:^",
"@remix-run/router": "^1.23.4",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, big extra dep for a small (?) thing. Is it possible to get resolveTo from somewhere else or inline?

Comment on lines +35 to +37
export function useOptionalAppHistory(): AppHistoryApi | undefined {
return useApiHolder().get(appHistoryApiRef);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still valid? Voting to give this the useAnalytics treatment

Comment on lines +95 to +99
* The `UNSAFE_*` names only exist from React Router v6 stable onwards. The v6
* beta this package still supports — see the `'6.0.0-beta.0 || ^6.3.0'` range
* the migration CLI writes, and the beta arm of `Link.test.tsx` — exports no
* `UNSAFE_` name at all, so each import is `undefined` there, and handing that
* to `useContext` throws before any hook below can answer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We removed RR 6 beta support ~18 months ago in the framework, so I think it's alright to drop support here too

Comment thread packages/core-components/package.json Outdated
"@backstage/config": "workspace:^",
"@backstage/core-plugin-api": "workspace:^",
"@backstage/errors": "workspace:^",
"@backstage/filter-predicates": "workspace:^",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used right? let's drop

}

/** Reads live backend state while retaining unchanged snapshot references. */
readonly getSnapshot = (): AppHistorySnapshot => this.refresh();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs a memo or smth

export const MATCH_ALL_ROUTE: BackstageRouteObject = {
caseSensitive: false,
path: '*',
element: 'match-all', // These elements aren't used, so we add in a bit of debug information

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well keep these if we can

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for contributing to Backstage! The changes in this pull request will be part of the 1.57.0 release, scheduled for Tue, 17 Nov 2026.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:catalog Related to the Catalog Project Area area:documentation Improvements or additions to documentation area:microsite Changes to backstage.io size:huge Huge pull requests receive a lower priority for reviews. waiting-for:merge The PR has been approved and is awaiting merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants