diff --git a/.changeset/chilled-mugs-learn.md b/.changeset/chilled-mugs-learn.md new file mode 100644 index 0000000000..b239134cf8 --- /dev/null +++ b/.changeset/chilled-mugs-learn.md @@ -0,0 +1,5 @@ +--- +'@backstage/core-api': patch +--- + +Export `SubRouteRef` type, and allow `SubRouteRef`s to be assigned to `plugin.routes`. diff --git a/packages/core-api/src/app/App.test.tsx b/packages/core-api/src/app/App.test.tsx index 4e7bf80624..c91eef1fb0 100644 --- a/packages/core-api/src/app/App.test.tsx +++ b/packages/core-api/src/app/App.test.tsx @@ -98,6 +98,12 @@ describe('Integration Test', () => { const plugin1 = createPlugin({ id: 'blob', + // Both absolute and sub route refs should be assignable to the plugin routes + routes: { + ref1: plugin1RouteRef, + ref2: plugin2RouteRef, + ref3: subRouteRef1, + }, externalRoutes: { extRouteRef1, extRouteRef2, diff --git a/packages/core-api/src/app/App.tsx b/packages/core-api/src/app/App.tsx index c20eb0824e..d2346e478c 100644 --- a/packages/core-api/src/app/App.tsx +++ b/packages/core-api/src/app/App.tsx @@ -53,7 +53,7 @@ import { import { IconComponent, IconComponentMap, IconKey } from '../icons'; import { BackstagePlugin } from '../plugin'; import { AnyRoutes } from '../plugin/types'; -import { RouteRef, ExternalRouteRef } from '../routing'; +import { RouteRef, ExternalRouteRef, SubRouteRef } from '../routing'; import { routeObjectCollector, routeParentCollector, @@ -75,10 +75,8 @@ import { SignInResult, } from './types'; -export function generateBoundRoutes( - bindRoutes: AppOptions['bindRoutes'], -): Map { - const result = new Map(); +export function generateBoundRoutes(bindRoutes: AppOptions['bindRoutes']) { + const result = new Map(); if (bindRoutes) { const bind: AppRouteBinder = (externalRoutes, targetRoutes: AnyRoutes) => { diff --git a/packages/core-api/src/plugin/types.ts b/packages/core-api/src/plugin/types.ts index c3b64d8cb6..2ad02b243d 100644 --- a/packages/core-api/src/plugin/types.ts +++ b/packages/core-api/src/plugin/types.ts @@ -15,7 +15,7 @@ */ import { ComponentType } from 'react'; -import { RouteRef, ExternalRouteRef } from '../routing'; +import { RouteRef, SubRouteRef, ExternalRouteRef } from '../routing'; import { AnyApiFactory } from '../apis/system'; export type RouteOptions = { @@ -70,7 +70,7 @@ export type Extension = { expose(plugin: BackstagePlugin): T; }; -export type AnyRoutes = { [name: string]: RouteRef }; +export type AnyRoutes = { [name: string]: RouteRef | SubRouteRef }; export type AnyExternalRoutes = { [name: string]: ExternalRouteRef }; diff --git a/packages/core-api/src/routing/index.ts b/packages/core-api/src/routing/index.ts index c6134cfe4f..c5441d5b23 100644 --- a/packages/core-api/src/routing/index.ts +++ b/packages/core-api/src/routing/index.ts @@ -16,6 +16,7 @@ export type { RouteRef, + SubRouteRef, AbsoluteRouteRef, ConcreteRoute, MutableRouteRef,