Skip to content

Commit 9810cfd

Browse files
committed
fix: match deeply nested '/' paths with query parameters
1 parent 287fc69 commit 9810cfd

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

modules/RouteNode.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export default class RouteNode {
5050
}
5151

5252
findSlashChild() {
53-
const slashChildren = this.getNonAbsoluteChildren().filter((child) => child.parser.path === '/');
53+
const slashChildren = this.getNonAbsoluteChildren()
54+
.filter((child) => child.parser && /^\/(\?|$)/.test(child.parser.path));
5455

5556
return slashChildren[0];
5657
}

test/main.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ describe('RouteNode', function () {
453453
it('should automatically match deep nested "/" children', () => {
454454
var node = new RouteNode('', '', [
455455
new RouteNode('section', '/section', [
456-
new RouteNode('top', '/'),
456+
new RouteNode('top', '/?withParam'),
457457
new RouteNode('part', '/:part')
458458
])
459459
]);
@@ -462,6 +462,19 @@ describe('RouteNode', function () {
462462
node.buildPath('section.top').should.eql('/section/');
463463
node.buildPath('section.top', {}, { trailingSlash: false }).should.eql('/section');
464464
});
465+
466+
it('should match deep nested "/" children with query params', () => {
467+
var node = new RouteNode('', '', [
468+
new RouteNode('app', '?:showVersion', [
469+
new RouteNode('admin', '/admin', [
470+
new RouteNode('users', '/?:sort?:page')
471+
])
472+
])
473+
]);
474+
475+
withoutMeta(node.matchPath('/admin/?page=1')).should.eql({ name: 'app.admin.users', params: { page: '1' }});
476+
withoutMeta(node.matchPath('/admin/')).should.eql({ name: 'app.admin.users', params: {}});
477+
});
465478
});
466479

467480

0 commit comments

Comments
 (0)