core-api/routing: allow duplicate registration if paths match

This commit is contained in:
Patrik Oldsberg
2020-09-20 14:41:42 +02:00
parent 735c1277d1
commit 240366572c
2 changed files with 5 additions and 2 deletions
@@ -44,6 +44,7 @@ describe('RouteRefRegistry', () => {
expect(registry.registerRoute([ref1, ref12], 'duplicate')).toBe(false);
expect(registry.registerRoute([ref2], '2')).toBe(true);
expect(registry.registerRoute([ref2], 'duplicate')).toBe(false);
expect(registry.registerRoute([ref2], '2')).toBe(true);
expect(registry.resolveRoute([], [ref1])).toBe('/1');
expect(registry.resolveRoute([], [ref11])).toBe(undefined);
@@ -68,8 +68,10 @@ class Node {
const lastRoute = routes[routes.length - 1];
const lastRouteRef = lastRoute[routeReference];
if (parentNode.children.has(lastRouteRef)) {
return false;
const existingNode = parentNode.children.get(lastRouteRef);
if (existingNode) {
return existingNode.path === path;
}
parentNode.children.set(lastRouteRef, new Node(path, parentNode));