diff --git a/src/core/extendRoutes.spec.ts b/src/core/extendRoutes.spec.ts index 730a0e647..101fae102 100644 --- a/src/core/extendRoutes.spec.ts +++ b/src/core/extendRoutes.spec.ts @@ -30,6 +30,15 @@ describe('EditableTreeNode', () => { expect(tree.children.get('foo')?.path).toBe('/foo') }) + it('allows filePath to be null on a route added in the editable tree', () => { + const tree = new PrefixTree(RESOLVED_OPTIONS) + const editable = new EditableTreeNode(tree) + + editable.insert('foo', null) + expect(editable.children).toHaveLength(1) + expect(editable.children[0]?.path).toBe('/foo') + }) + it('keeps nested routes flat', () => { const tree = new PrefixTree(RESOLVED_OPTIONS) const editable = new EditableTreeNode(tree) diff --git a/src/core/extendRoutes.ts b/src/core/extendRoutes.ts index 8692d73e1..fe702e302 100644 --- a/src/core/extendRoutes.ts +++ b/src/core/extendRoutes.ts @@ -38,7 +38,7 @@ export class EditableTreeNode { * @param filePath - file path * @returns the new editable route node */ - insert(path: string, filePath: string) { + insert(path: string, filePath: string | null) { // adapt paths as they should match a file system let addBackLeadingSlash = false if (path.startsWith('/')) { diff --git a/src/core/tree.ts b/src/core/tree.ts index 501a7c3c3..3c09203fb 100644 --- a/src/core/tree.ts +++ b/src/core/tree.ts @@ -90,9 +90,9 @@ export class TreeNode { * @param path - path segment to insert, already parsed (e.g. users/:id) * @param filePath - file path, defaults to path for convenience and testing */ - insertParsedPath(path: string, filePath: string = path): TreeNode { - // TODO: allow null filePath? - const isComponent = true + insertParsedPath(path: string, filePath: string | null = path): TreeNode { + // Allow null filePath to be handled + const isComponent = filePath !== null const node = new TreeNode( {