File tree Expand file tree Collapse file tree 2 files changed +26
-8
lines changed
packages/router/src/unplugin/core Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 */
You can’t perform that action at this time.
0 commit comments