diff --git a/packages/core-compat-api/src/collectLegacyRoutes.test.tsx b/packages/core-compat-api/src/collectLegacyRoutes.test.tsx
index 486c373991..85fed83e8c 100644
--- a/packages/core-compat-api/src/collectLegacyRoutes.test.tsx
+++ b/packages/core-compat-api/src/collectLegacyRoutes.test.tsx
@@ -30,6 +30,7 @@ describe('collectLegacyRoutes', () => {
} />
} />
} />
+ } />
,
);
@@ -85,6 +86,12 @@ describe('collectLegacyRoutes', () => {
disabled: false,
defaultConfig: { path: 'puppetdb' },
},
+ {
+ id: 'plugin.puppetDb.page2',
+ attachTo: { id: 'core.routes', input: 'routes' },
+ disabled: false,
+ defaultConfig: { path: 'puppetdb' },
+ },
{
id: 'apis.plugin.puppetdb.service',
attachTo: { id: 'core', input: 'apis' },
diff --git a/packages/core-compat-api/src/collectLegacyRoutes.tsx b/packages/core-compat-api/src/collectLegacyRoutes.tsx
index 2b149e6285..8178de2876 100644
--- a/packages/core-compat-api/src/collectLegacyRoutes.tsx
+++ b/packages/core-compat-api/src/collectLegacyRoutes.tsx
@@ -62,7 +62,10 @@ Existing tasks:
export function collectLegacyRoutes(
flatRoutesElement: JSX.Element,
): BackstagePlugin[] {
- const results = new Array();
+ const createdPluginIds = new Map<
+ LegacyBackstagePlugin,
+ Extension[]
+ >();
React.Children.forEach(
flatRoutesElement.props.children,
@@ -93,13 +96,18 @@ export function collectLegacyRoutes(
);
const pluginId = plugin.getId();
- const path: string = route.props.path;
- const detectedExtensions = new Array>();
+ const detectedExtensions =
+ createdPluginIds.get(plugin) ?? new Array>();
+ createdPluginIds.set(plugin, detectedExtensions);
+
+ const path: string = route.props.path;
detectedExtensions.push(
createPageExtension({
- id: `plugin.${pluginId}.page`,
+ id: `plugin.${pluginId}.page${
+ detectedExtensions.length ? detectedExtensions.length + 1 : ''
+ }`,
defaultPath: path[0] === '/' ? path.slice(1) : path,
routeRef: routeRef ? convertLegacyRouteRef(routeRef) : undefined,
@@ -115,23 +123,20 @@ export function collectLegacyRoutes(
),
}),
);
+ },
+ );
- detectedExtensions.push(
+ return Array.from(createdPluginIds).map(([plugin, extensions]) =>
+ createPlugin({
+ id: plugin.getId(),
+ extensions: [
+ ...extensions,
...Array.from(plugin.getApis()).map(factory =>
createApiExtension({
factory,
}),
),
- );
-
- results.push(
- createPlugin({
- id: plugin.getId(),
- extensions: detectedExtensions,
- }),
- );
- },
+ ],
+ }),
);
-
- return results;
}