diff --git a/packages/transport-commons/src/routing/router.ts b/packages/transport-commons/src/routing/router.ts index c2be1631f0..e45e6674b3 100644 --- a/packages/transport-commons/src/routing/router.ts +++ b/packages/transport-commons/src/routing/router.ts @@ -57,6 +57,7 @@ export class RouteNode { remove(path: string[]) { if (path.length === this.depth) { + delete this.data return } diff --git a/packages/transport-commons/test/routing/router.test.ts b/packages/transport-commons/test/routing/router.test.ts index 307aeccbd8..df2d0020af 100644 --- a/packages/transport-commons/test/routing/router.test.ts +++ b/packages/transport-commons/test/routing/router.test.ts @@ -118,4 +118,22 @@ describe('router', () => { r.remove('/hello/here/thing') assert.ok(!r.root.hasChildren) }) + + it('re-initialize a service with children. (#3432)', () => { + const r = new Router() + + r.insert('/hello', 'one') + r.insert('/hello/world', 'else') + + assert.deepStrictEqual(r.lookup('hello'), { params: { }, data: 'one' }) + + r.remove('/hello') + + assert.deepStrictEqual(r.lookup('hello/world'), { params: {}, data: 'else' }) + + r.insert('/hello', 'two') + + assert.deepStrictEqual(r.lookup('hello'), { params: { }, data: 'two' }) + assert.deepStrictEqual(r.lookup('hello/world'), { params: {}, data: 'else' }) + }) })