@@ -10,7 +10,11 @@ import type {
1010 MatcherQueryParams ,
1111} from './matchers/matcher-pattern'
1212import { MatcherPatternPathStatic } from './matchers/matcher-pattern'
13- import type { MatcherPatternQuery } from './matchers/matcher-pattern-query'
13+ import {
14+ MatcherPatternQueryParam ,
15+ type MatcherPatternQuery ,
16+ } from './matchers/matcher-pattern-query'
17+ import { PARAM_PARSER_INT } from './matchers/param-parsers'
1418import {
1519 EMPTY_PATH_PATTERN_MATCHER ,
1620 USER_ID_PATH_PATTERN_MATCHER ,
@@ -460,6 +464,45 @@ describe('fixed resolver', () => {
460464 fullPath : '/?existing=value&page=10#current' ,
461465 } )
462466 } )
467+
468+ describe ( 'removes a query param set to undefined' , ( ) => {
469+ const resolver = createFixedResolver ( [
470+ {
471+ name : 'list' ,
472+ path : EMPTY_PATH_PATTERN_MATCHER ,
473+ query : [
474+ new MatcherPatternQueryParam (
475+ 'page' ,
476+ 'page' ,
477+ 'value' ,
478+ PARAM_PARSER_INT ,
479+ 1
480+ ) ,
481+ new MatcherPatternQueryParam ( 'q' , 'q' , 'value' ) ,
482+ ] ,
483+ hash : ANY_HASH_PATTERN_MATCHER ,
484+ } ,
485+ ] )
486+ const current = resolver . resolve ( '/?page=5&q=a&other=x#h' )
487+
488+ it ( 'with a default' , ( ) => {
489+ expect (
490+ resolver . resolve ( { params : { page : undefined } } , current )
491+ ) . toMatchObject ( {
492+ fullPath : '/?q=a&other=x#h' ,
493+ params : { page : 1 , q : 'a' } ,
494+ } )
495+ } )
496+
497+ it ( 'without a default' , ( ) => {
498+ expect (
499+ resolver . resolve ( { params : { q : undefined } } , current )
500+ ) . toMatchObject ( {
501+ fullPath : '/?page=5&other=x#h' ,
502+ params : { page : 5 , q : undefined } ,
503+ } )
504+ } )
505+ } )
463506 } )
464507
465508 describe ( 'absolute locations' , ( ) => {
0 commit comments