diff --git a/packages/core-compat-api/src/collectLegacyRoutes.test.tsx b/packages/core-compat-api/src/collectLegacyRoutes.test.tsx
index 240aa33e2c..b99d581983 100644
--- a/packages/core-compat-api/src/collectLegacyRoutes.test.tsx
+++ b/packages/core-compat-api/src/collectLegacyRoutes.test.tsx
@@ -279,4 +279,58 @@ describe('collectLegacyRoutes', () => {
screen.findByText('plugins: test'),
).resolves.toBeInTheDocument();
});
+
+ it('should throw if invalid Route has been detected', async () => {
+ const plugin = createPlugin({
+ id: 'test',
+ });
+ const routeRef = createRouteRef({ id: 'test' });
+ const Page = plugin.provide(
+ createRoutableExtension({
+ name: 'Test',
+ mountPoint: routeRef,
+ component: () =>
+ Promise.resolve(() => {
+ const app = useApp();
+ return
plugins: {app.getPlugins().map(p => p.getId())}
;
+ }),
+ }),
+ );
+
+ expect(() =>
+ collectLegacyRoutes(
+
+ } />
+ } />
+
+ ,
+ ),
+ ).toThrow(/Invalid has no path', async () => {
+ const plugin = createPlugin({
+ id: 'test',
+ });
+ const routeRef = createRouteRef({ id: 'test' });
+ const Page = plugin.provide(
+ createRoutableExtension({
+ name: 'Test',
+ mountPoint: routeRef,
+ component: () =>
+ Promise.resolve(() => {
+ const app = useApp();
+ return plugins: {app.getPlugins().map(p => p.getId())}
;
+ }),
+ }),
+ );
+
+ expect(() =>
+ collectLegacyRoutes(
+
+ } />
+ ,
+ ),
+ ).toThrow(/ element with invalid path/);
+ });
});
diff --git a/packages/core-compat-api/src/collectLegacyRoutes.tsx b/packages/core-compat-api/src/collectLegacyRoutes.tsx
index 4d560b81d5..847c0805cb 100644
--- a/packages/core-compat-api/src/collectLegacyRoutes.tsx
+++ b/packages/core-compat-api/src/collectLegacyRoutes.tsx
@@ -173,9 +173,8 @@ export function collectLegacyRoutes(
(route: ReactNode) => {
// TODO(freben): Handle feature flag and permissions framework wrapper elements
if (!React.isValidElement(route) || route.type !== Route) {
- return;
+ throw new Error('Invalid element has been detected.');
}
-
const routeElement = route.props.element;
const path: string | undefined = route.props.path;
const plugin = getComponentData(
@@ -186,7 +185,12 @@ export function collectLegacyRoutes(
routeElement,
'core.mountPoint',
);
- if (!plugin || !path) {
+ if (path === undefined) {
+ throw new Error(
+ ` element with invalid path has been detected. Please make sure to pass the path's props`,
+ );
+ }
+ if (!plugin) {
return;
}