Skip to content

Commit

Permalink
fix(options): dotNesting
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed May 1, 2023
1 parent a4d2685 commit b7abc9b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/core/tree.spec.ts
Expand Up @@ -464,4 +464,38 @@ describe('Tree', () => {
expect(aNested.value.components.get('default')).toBe('a/nested.page.vue')
expect(aNested.fullPath).toBe('/a/nested')
})

describe('dot nesting', () => {
it('transforms dots into nested routes by default', () => {
const tree = createPrefixTree(DEFAULT_OPTIONS)
tree.insert('users.new.vue')
expect(tree.children.size).toBe(1)
const users = tree.children.get('users.new')!
expect(users.value).toMatchObject({
rawSegment: 'users.new',
pathSegment: 'users/new',
path: '/users/new',
_type: TreeNodeType.static,
})
})

it.only('can ignore dot nesting', () => {
const tree = createPrefixTree({
...DEFAULT_OPTIONS,
pathParser: {
dotNesting: false,
},
})
tree.insert('1.2.3-lesson.vue')
expect(tree.children.size).toBe(1)
const lesson = tree.children.get('1.2.3-lesson')!

expect(lesson.value).toMatchObject({
rawSegment: '1.2.3-lesson',
pathSegment: '1.2.3-lesson',
path: '/1.2.3-lesson',
_type: TreeNodeType.static,
})
})
})
})
2 changes: 1 addition & 1 deletion src/core/tree.ts
Expand Up @@ -45,7 +45,7 @@ export class TreeNode {
this.value = createTreeNodeValue(
filePath,
parent?.value,
options.treeNodeOptions
options.treeNodeOptions || options.pathParser
)
}

Expand Down

0 comments on commit b7abc9b

Please sign in to comment.