Skip to content

Commit fea47d7

Browse files
committed
fix: pass query params options to parse and build functions
1 parent 2280a7d commit fea47d7

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

modules/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const buildPathFromSegments = (
9191
return acc
9292
}, {})
9393

94-
const searchPart = build(searchParamsObject)
94+
const searchPart = build(searchParamsObject, options.queryParams)
9595

9696
const path = segments
9797
.reduce((path, segment) => {

modules/matchChildren.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const matchChildren = (
3535
if (!child.children.length) {
3636
match = child.parser.test(segment, {
3737
caseSensitive,
38-
strictTrailingSlash
38+
strictTrailingSlash,
39+
queryParams: options.queryParams
3940
})
4041
}
4142

@@ -67,7 +68,8 @@ const matchChildren = (
6768

6869
const { querystring } = omit(
6970
getSearch(segment.replace(consumedPath, '')),
70-
child.parser.queryParams
71+
child.parser.queryParams,
72+
options.queryParams
7173
)
7274
remainingPath =
7375
getPath(remainingPath) + (querystring ? `?${querystring}` : '')
@@ -95,7 +97,10 @@ const matchChildren = (
9597
remainingPath.indexOf('?') === 0
9698
) {
9799
// unmatched queryParams in non strict mode
98-
const remainingQueryParams = parse(remainingPath.slice(1))
100+
const remainingQueryParams = parse(
101+
remainingPath.slice(1),
102+
options.queryParams
103+
)
99104

100105
Object.keys(remainingQueryParams).forEach(
101106
name =>

test/main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,21 @@ describe('RouteNode', function() {
734734
node.matchPath('/A', { caseSensitive: false }).name.should.equal('a')
735735
should.not.exist(node.matchPath('/A', { caseSensitive: true }))
736736
})
737+
738+
it('should pass query parameters options to path-parser', () => {
739+
const node = new RouteNode('', '', [new RouteNode('a', '/a?b&c')])
740+
const options = {
741+
queryParams: {
742+
booleanFormat: 'string',
743+
arrayFormat: 'brackets'
744+
}
745+
}
746+
747+
node.matchPath('/a?b=true&c[]=1', options).params.should.eql({
748+
b: true,
749+
c: ['1']
750+
})
751+
})
737752
})
738753

739754
function getRoutes(trailingSlash) {

0 commit comments

Comments
 (0)