Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/core/extendRoutes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/core/extendRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')) {
Expand Down
6 changes: 3 additions & 3 deletions src/core/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down