React Router v7 page adapter. Injects library context projected from the
framework's AppHistoryApi and never writes window.history via
push/replace/go.
children are rendered as opaque content inside that context — an existing
React Router <Routes> tree composed by the page itself keeps working
(relative Links, nested <Routes>, useParams, and so on), as does the
sub-page the framework routed to. This adapter builds no routes of its own:
which sub-page of a page is showing is decided by the framework's own route
matching, one level above.
Programmatic back and forward (navigate(-1)) traverse the app-owned
browser history.
Declare it by rendering it inside the lazily loaded page or sub-page component that
should get the context:
// In the lazily loaded page component module: exportfunctionSettingsPage() { return ( <ReactRouterV7PageRouter> {routes} </ReactRouterV7PageRouter> ); }
In a sub-page's component it scopes itself to that sub-page rather than to
the page above it, because the sub-page's own mount is what is in context
there. Adapters nest rather than replace one another, so a v7 sub-page works
under a page rendered by another routing library, and the reverse.
Scoping needs two things: a page mount, saying which part of the URL belongs
to the page, and a registered AppHistoryApi to project a location from.
With either missing this adapter renders children untouched and demands
nothing of the surrounding app — no API provider, no framework context. That
passthrough is what lets one component wrap itself in the adapter and still
ship for both frontend systems: under the old frontend system there is no
page mount and no app history, and the wrap has to be invisible rather than
a crash. The same holds in a plugin's own render() unit tests.
React Router v7 page adapter. Injects library context projected from the framework's
AppHistoryApiand never writeswindow.historyvia push/replace/go.childrenare rendered as opaque content inside that context — an existing React Router<Routes>tree composed by the page itself keeps working (relative Links, nested<Routes>,useParams, and so on), as does the sub-page the framework routed to. This adapter builds no routes of its own: which sub-page of a page is showing is decided by the framework's own route matching, one level above.Programmatic back and forward (
navigate(-1)) traverse the app-owned browser history.Declare it by rendering it inside the lazily loaded page or sub-page component that should get the context:
In a sub-page's component it scopes itself to that sub-page rather than to the page above it, because the sub-page's own mount is what is in context there. Adapters nest rather than replace one another, so a v7 sub-page works under a page rendered by another routing library, and the reverse.
Scoping needs two things: a page mount, saying which part of the URL belongs to the page, and a registered
AppHistoryApito project a location from. With either missing this adapter renderschildrenuntouched and demands nothing of the surrounding app — no API provider, no framework context. That passthrough is what lets one component wrap itself in the adapter and still ship for both frontend systems: under the old frontend system there is no page mount and no app history, and the wrap has to be invisible rather than a crash. The same holds in a plugin's ownrender()unit tests.