diff --git a/packages/core-app-api/src/routing/collectors.compat.test.tsx b/packages/core-app-api/src/routing/collectors.compat.test.tsx
index 7ee19b9fd2..e1333a070a 100644
--- a/packages/core-app-api/src/routing/collectors.compat.test.tsx
+++ b/packages/core-app-api/src/routing/collectors.compat.test.tsx
@@ -187,7 +187,9 @@ describe.each(['beta', 'stable'])('react-router %s', rrVersion => {
{null}
- } />
+
+ } />
+
{false}
@@ -211,7 +213,7 @@ describe.each(['beta', 'stable'])('react-router %s', rrVersion => {
expect(sortedEntries(routing.paths)).toEqual([
[ref1, 'foo'],
[ref2, 'bar/:id'],
- [ref3, 'baz'],
+ [ref3, rrVersion === 'beta' ? '/baz' : 'baz'],
[ref4, 'divsoup'],
[ref5, 'blop'],
]);
@@ -227,7 +229,11 @@ describe.each(['beta', 'stable'])('react-router %s', rrVersion => {
'foo',
[ref1],
[
- routeObj('bar/:id', [ref2], [routeObj('baz', [ref3])]),
+ routeObj(
+ 'bar/:id',
+ [ref2],
+ [routeObj(rrVersion === 'beta' ? '/baz' : 'baz', [ref3])],
+ ),
routeObj('blop', [ref5]),
],
),
diff --git a/packages/core-app-api/src/routing/collectors.stable.test.tsx b/packages/core-app-api/src/routing/collectors.stable.test.tsx
index 6c2767621f..2324ea5b69 100644
--- a/packages/core-app-api/src/routing/collectors.stable.test.tsx
+++ b/packages/core-app-api/src/routing/collectors.stable.test.tsx
@@ -249,6 +249,46 @@ describe('discovery', () => {
]);
});
+ it('should handle absolute route paths', () => {
+ const root = (
+
+
+ }>
+
+ } />
+
+
+ }>
+ } />
+ } />
+
+
+
+ );
+
+ const { routing } = traverseElementTree({
+ root,
+ discoverers: [childDiscoverer, routeElementDiscoverer],
+ collectors: {
+ routing: routingV2Collector,
+ },
+ });
+ expect(sortedEntries(routing.paths)).toEqual([
+ [ref1, 'foo'],
+ [ref2, 'bar/:id'],
+ [ref3, 'baz'],
+ [ref4, 'divsoup'],
+ [ref5, 'blop'],
+ ]);
+ expect(sortedEntries(routing.parents)).toEqual([
+ [ref1, undefined],
+ [ref2, ref1],
+ [ref3, undefined],
+ [ref4, ref3],
+ [ref5, ref3],
+ ]);
+ });
+
it('should use the route aggregator key to bind child routes to the same path', () => {
const root = (
@@ -309,11 +349,11 @@ describe('discovery', () => {
}>
-
+
}>
- } />
+ } />
diff --git a/packages/core-app-api/src/routing/collectors.tsx b/packages/core-app-api/src/routing/collectors.tsx
index 81a263eb70..1a2bd2f431 100644
--- a/packages/core-app-api/src/routing/collectors.tsx
+++ b/packages/core-app-api/src/routing/collectors.tsx
@@ -87,10 +87,10 @@ export const routingV2Collector = createCollector(
objects: new Array(),
}),
(acc, node, parent, ctx?: RoutingV2CollectorContext) => {
- const path: unknown = node.props?.path;
+ const pathProp: unknown = node.props?.path;
const mountPoint = getComponentData(node, 'core.mountPoint');
- if (mountPoint && path) {
+ if (mountPoint && pathProp) {
throw new Error(
`Path property may not be set directly on a routable extension "${stringifyNode(
node,
@@ -109,13 +109,15 @@ export const routingV2Collector = createCollector(
const parentChildren = ctx?.obj?.children ?? acc.objects;
- if (path) {
- if (typeof path !== 'string') {
+ if (pathProp) {
+ if (typeof pathProp !== 'string') {
throw new Error(
`Element path must be a string at "${stringifyNode(node)}"`,
);
}
+ const path = pathProp.startsWith('/') ? pathProp.slice(1) : pathProp;
+
const elementProp = node.props.element;
if (getComponentData(node, 'core.gatherMountPoints')) {
@@ -149,7 +151,7 @@ export const routingV2Collector = createCollector(
const [extension, ...others] = collectSubTree(elementProp);
if (others.length > 0) {
throw new Error(
- `Route element with path "${path}" may not contain multiple routable extensions`,
+ `Route element with path "${pathProp}" may not contain multiple routable extensions`,
);
}
if (!extension) {