Skip to content

Commit b28a71e

Browse files
committed
fix: cleanup old route overrides
1 parent 7aa607f commit b28a71e

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

packages/router/src/unplugin/core/tree.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,22 @@ describe('Tree', () => {
814814
expect(`"(home" is missing the closing ")"`).toHaveBeenWarned()
815815
})
816816

817+
it('overrides existing properties with setCustomRouteBlock', () => {
818+
const tree = new PrefixTree(RESOLVED_OPTIONS)
819+
const page = tree.insert('page', 'page.vue')
820+
page.setCustomRouteBlock('page.vue', {
821+
alias: ['/home'],
822+
name: 'Page',
823+
})
824+
// same as editing the file
825+
page.setCustomRouteBlock('page.vue', {
826+
// we drop the name
827+
alias: ['/other'],
828+
})
829+
expect(page.alias).toEqual(['/other'])
830+
expect(page.name).toBe('/page')
831+
})
832+
817833
describe('path regexp', () => {
818834
function checkRegexp(
819835
path: string,

packages/router/src/unplugin/core/tree.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ export class TreeNode {
147147
}
148148

149149
/**
150-
* Saves a custom route block for a specific file path. The file path is used as a key. Some special file paths will
151-
* have a lower or higher priority.
150+
* Saves a custom route block for a specific file path. The file path is used
151+
* as a key. Some special file paths will have a lower or higher priority.
152152
*
153153
* @param filePath - file path where the custom block is located
154154
* @param routeBlock - custom block to set
@@ -157,12 +157,7 @@ export class TreeNode {
157157
filePath: string,
158158
routeBlock: CustomRouteBlock | undefined
159159
) {
160-
// FIXME: No, we can't do this because we are adding stuff this way like aliases are never removed
161-
// Use mergeOverride to preserve existing override properties (e.g. name: false for _parent routes)
162-
// this.value.setOverride(filePath, routeBlock)
163-
if (routeBlock) {
164-
this.value.mergeOverride(filePath, routeBlock)
165-
}
160+
this.value.setOverride(filePath, routeBlock)
166161
}
167162

168163
/**
@@ -272,6 +267,13 @@ export class TreeNode {
272267
return this.value.fullPath
273268
}
274269

270+
/**
271+
* Returns the alias of the node
272+
*/
273+
get alias(): string[] {
274+
return this.value.alias
275+
}
276+
275277
/**
276278
* Object of components (filepaths) for this node.
277279
*/

0 commit comments

Comments
 (0)